Jump to content
Larry Ullman's Book Forums

x_wd11

Members
  • Posts

    19
  • Joined

  • Last visited

Posts posted by x_wd11

  1. Would you know how to extract the number of user that is in a particular table?

    $q = "SELECT COUNT(user) FROM table1 WHERE user = 'glenn'";
    $r = @mysqli_query($dbc, $q);
    //$num = mysqli_num_rows($r);
    //$id = mysqli_fetch_field($r);
    //$id = mysqli_fetch_array($r);
    $id = mysqli_fetch_assoc($r);
    
    echo 'r user number '. $r .'<br>';
    echo 'n user number '. $num .'<br>';
    echo 'n user number '. $id .'<br>';
    
    
    I get different errors BUT no result!

    Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in

    Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in

    Thank you much.

  2. In a file that has several "functions" f1, f2, fn you need to put the ".../mysqli.php" call to every one of the functions, correct? Or can you have it at the top of the file and just use "mysqli_query($dbc,$x)" in each of the functions referencing mysqli? In my file it is not visible to functions if trying to set the sql connection at the top of the file. Thanks

  3. Would you tell me how to find out where this is coming from:

    Notice: Constant DB_USER already defined in C:\mysqli.php on line 8
    
    Notice: Constant DB_PASSWORD already defined in C:\mysqli.php on line 9
    
    Notice: Constant DB_HOST already defined in C:\mysqli.php on line 10
    
    Notice: Constant DB_NAME already defined in C:\mysqli.php on line 11

    In some cases it works fine but, it does not show up but now it is showing and cannot find where it is generated. Thank  you.
     

  4. I do NOT understand this:  "password_verify($p, $row['passward'])"
     where: $p = 123456
     while this is in DB: ba3253876aed6bc22d4a6ff53d8406c6ad864195ed144ab5c87621b6c233b548baeae6956df346ec8c17f5ea10f35ee3cbc514797ed7ddd3145464e2a0bab413

    ???

    if (empty($errors)) { // If everything's OK.
            $q = "SELECT user_id, first_name, passward FROM users WHERE user='xyz' AND passward=SHA2('$p', 512)";
            $r = mysqli_query($dbc, $q); // Run the query.
            
            // Check the result:
            if (mysqli_num_rows($r) == 1) {
                // Fetch the record:
                $row = mysqli_fetch_array($r, MYSQLI_ASSOC);
                
                // Return true and the record:
               // Check the password:
                if (password_verify($p, $row['passward'])) {
                    unset($row['passward']);
                    return [true, $row];
                } else {
                    $errors[] = 'The user name and password do not match those on file.';
                }           //   - The user name and password entered do not match those on file.  ????
                
            } else { // Not a match! 
                $errors[] = 'The user-name and password entered do not match those on file.';
            }

     

  5. Which table do I insert to first, table1 that does have the FOREIGN KEY (file_id) REFERENCES userinfo(user_id) or the table2 that does NOT have the constrain?
     I am trying to insert into both tables at a sequence, table1 and then table2, BUT I get this error: "Cannot add or update a child row: a foreign key constraint fails...!"
    Should I insert first into table2 and then into table1? Thanks

     $q1 = "INSERT INTO table1 ...
     $r1 = @mysqli_query($dbc, $q1); // Run the query.

     if ($r1) { // If it ran OK.
                $q2 = "INSERT INTO table2 ...
                $r2 = @mysqli_query($dbc, $q2);
                if($r2){...

  6. I do get the right results when I enter the query in workbench.  I found that when I call login screen and enter “correct values” and execute, it clears the fields and stays at the login screen BUT when I enter “incorrect values" it executes properly and displays errors that those values are incorrect!?  After a day of messing with that I finally checked the script and it was from the earlier chapter. It works now. Thanks

  7. what is the difference between your sql call and my sql call:

            // $q = "SELECT user_id, first_name FROM users WHERE $userid AND pass=SHA2('$p', 512)";
            $q = "SELECT user_id, first_name, username FROM users WHERE username='$uname' AND pass=SHA2('$p', 512)";
            $r = @mysqli_query($dbc, $q); // Run the query.
            
            // Check the result:
            if (mysqli_num_rows($r) == 1) {
                echo 'check_login == 1';
                // Fetch the record:
                $row = mysqli_fetch_array($r, MYSQLI_ASSOC);
                
                // Return true and the record:
                return [true, $row];
                
            } else { // Not a match!        //  'The email address and password entered do not match those on file.';
                $errors[] = 'The user name and password entered do not match those on file.';
            }

    it does not return anything, it just stays in index.php calling login screen over and over!? It does not enters the "if" statement.  Thank you

  8. Do I set the cookie first or session?

    <li><?php 					// Create a login/logout link:
    					if ( (isset($_COOKIE['user_id'])) && (basename($_SERVER['PHP_SELF']) != 'logout.php') ) {
    						if (isset($_SESSION['user_id'])) {
    							echo '<a href="logout.php">Logout</a>';
    						} else {
    							echo '<a href="login.php">Login</a>';
    						}
    					} else {
    						echo '<a href="login.php">Login</a>';
    					}
    				?></li>

    Or do I set the cookie at a later time?  Also, there's a session call in login and then in loggedin, both files need to call for session start? I do not believe you say that anywhere in the chapter if both are required. Thanks

  9. Well, I jumped over all the chapters right to the 17th and 18th and combined users table with the other user table, so I had 2 such tables in one DB ... . Now I am back where I should be and already made it to ch11. One has to be very creative to follow thru but I did figure out finally how to work with the pictures. Not easy some of the stuff to follow but it can be done. I think I can skip over the transfers, it's more about shopping card I guess, it's not used for my web idea.  Thanks.

  10. I cannot figure out where I am redefining these values:

    An error occurred in script 'C:\www\httdocs\ulproject\mysqli_connect.php' on line 8: 
    Constant DB_USER already defined
    
    Warning: print_r(): Couldn't fetch mysqli_result in 
    C:\www\httdocs\ulproject\includes\config.inc.php on line 47
    
    An error occurred in script 'C:\www\httdocs\ulproject\mysqli_connect.php' on line 9: 
    Constant DB_PASSWORD already defined
    
     my_error_handler(8, Constant DB_HOST already defined, 
    
    Warning: print_r(): Property access is not allowed yet in 
    C:\www\httdocs\ulproject\includes\config.inc.php on line 47
    
    Warning: print_r(): Couldn't fetch mysqli_result in 
    C:\www\httdocs\ulproject\includes\config.inc.php on line 47

    You probably know where these issues are coming from, would you let me know, thanks much.

  11. I get an error while setting up db for ch17:  ERROR 1366 (HY000) at line 75: Incorrect string value: '\xEAs' for column 'lang' at row 2, it is the line right bellow the # ERROR ... ? Would you help figuring out the cause? Thank  you.

    CREATE TABLE words (
    word_id TINYINT UNSIGNED NOT NULL AUTO_INCREMENT,
    lang_id TINYINT UNSIGNED NOT NULL,
    title VARCHAR(80) NOT NULL,
    intro TINYTEXT NOT NULL,
    home VARCHAR(30) NOT NULL,
    forum_home VARCHAR(40) NOT NULL,
    language VARCHAR(40) NOT NULL,
    register VARCHAR(30) NOT NULL,
    login VARCHAR(30) NOT NULL,
    logout VARCHAR(30) NOT NULL,
    new_thread VARCHAR(40) NOT NULL,
    subject VARCHAR(30) NOT NULL,
    body VARCHAR(30) NOT NULL,
    submit VARCHAR(30) NOT NULL,
    posted_on VARCHAR(30) NOT NULL,
    posted_by VARCHAR(30) NOT NULL,
    replies VARCHAR(30) NOT NULL,
    latest_reply VARCHAR(40) NOT NULL,
    post_a_reply VARCHAR(40) NOT NULL,
    PRIMARY KEY (word_id),
    UNIQUE (lang_id)
    );
    # ERROR 1366 (HY000) at line 75: Incorrect string value: '\xEAs' for column 'lang' at row 2
    INSERT INTO languages (lang, lang_eng) VALUES
    ('English', 'English'),
    ('Português', 'Portuguese'),
    ('Français', 'French'),
    ('Norsk', 'Norwegian'),
    ('Romanian', 'Romanian'),
    ('Ελληνικά', 'Greek'),
    ('Deutsch', 'German'),
    ('Srpski', 'Serbian'),
    ('日本語', 'Japanese'),
    ('Nederlands', 'Dutch');

     

×
×
  • Create New...