Jump to content
Larry Ullman's Book Forums


  • Content Count

  • Joined

  • Last visited

Community Reputation

0 Neutral

About x_wd11

  • Rank
  1. Instead giving me some warnings, shouldn't it tell me it is not connected to DB! I believe that what it did before, my old setup, I guess something changed that is different from the old. Sorry for bugging you with details.
  2. 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 pa
  3. Well, in your book I found the way you pass mysqli call via a function and so I am using it and it works fine. Thank you.
  4. 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
  5. 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.
  6. I think I got it, I got some mess in those scripts, cannot keep track of them somehow. Wrong script, but it was working and then it quit, that is why I got confused, the later scripts do have a different setup and so easy to get carried away with the implementation that should be using different script.
  7. 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 = mysql
  8. I found this link https://codeburst.io/insert-with-select-statement-for-columns-with-foreign-key-constraint-in-mysql-with-examples-f9ab57c8e4dd and fixing some of the errors in my query I got it working.
  9. 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($
  10. Sha1() pg414 Ch12: … 3. Save the file and place it in your web directory. … How do you exactly do that, where do you describe this process? Does each logged user have its own file or is it one dedicated for the purpose of security? Thank you
  11. 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
  12. 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:
  13. 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
  14. 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.
  15. 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 Warni
  • Create New...