Marie Posted November 18, 2018 Share Posted November 18, 2018 I have been updating a website with the scripting from this book. A piece of code I have is not working with the new php and I have reworked this several times. The following is the error message that I get in the server error log - PHP Fatal error: Can't use function return value in write context in /hermes/bosnacweb04/bosnacweb04aj/b717/nf.xxxxxxxxx/public_html/xxxxxxxx.com/Login.php on line 137 Line 37 would be the following - if (mysqli_num_rows($r) = $username) { <?php // Show the user info or the login form: if (isset($_SESSION['user_id'])) { // Show basic user options: $q = "SELECT user_id, username FROM users WHERE user_id={$_SESSION['user_id']}"; $r = mysqli_query ($db, $q); //if (mysqli_num_rows($r) > 0) { if (mysqli_num_rows($r) = $username) { //while ($row = mysqli_fetch_array($r, MYSQLI_NUM)) { while ($r = mysqli_fetch_array($r, MYSQLI_NUM)) { // Display the username and heading echo "<p><h2a>Hello $username!</p>"; } } Thanks Link to comment Share on other sites More sharing options...
Marie Posted November 18, 2018 Author Share Posted November 18, 2018 2 hours ago, Marie said: I have been updating a website with the scripting from this book. A piece of code I have is not working with the new php and I have reworked this several times. The following is the error message that I get in the server error log - PHP Fatal error: Can't use function return value in write context in /hermes/bosnacweb04/bosnacweb04aj/b717/nf.xxxxxxxxx/public_html/xxxxxxxx.com/Login.php on line 137 Line 137 would be the following - if (mysqli_num_rows($r) = $username) { <?php // Show the user info or the login form: if (isset($_SESSION['user_id'])) { // Show basic user options: $q = "SELECT user_id, username FROM users WHERE user_id={$_SESSION['user_id']}"; $r = mysqli_query ($db, $q); //if (mysqli_num_rows($r) > 0) { if (mysqli_num_rows($r) = $username) { //while ($row = mysqli_fetch_array($r, MYSQLI_NUM)) { while ($r = mysqli_fetch_array($r, MYSQLI_NUM)) { // Display the username and heading echo "<p><h2a>Hello $username!</p>"; } } Thanks Link to comment Share on other sites More sharing options...
Marie Posted November 18, 2018 Author Share Posted November 18, 2018 Sorry about the double posting above. I was hoping to delete my original post so I could correct it. The error message refers to line 137 not 37. Anyway, the original code I used came from the first edition of the eCommerce book which uses "rows". So the original code would have written <p><h2>Hello $row[1]!</p>. Link to comment Share on other sites More sharing options...
Larry Posted November 19, 2018 Share Posted November 19, 2018 I think you're missing an equals sign. This code-- if (mysqli_num_rows($r) = $username) { --is trying to assign the value of $username to mysqli_num_rows($r), which of course isn't possible. You want == $username instead. But that still won't work because mysqli_num_rows() is going to return an array and what you need to do is compare an element in that array to $username. Link to comment Share on other sites More sharing options...
MelissaMMDP Posted December 6, 2018 Share Posted December 6, 2018 (edited) I also noticed you have an extra "a" in the h2 tag and you need to close this tag. echo "<p><h2a>Hello $username!</p>"; should be: echo "<p><h2>Hello $username!</h2></p>"; Edited December 6, 2018 by MelissaMMDP Link to comment Share on other sites More sharing options...
Larry Posted December 7, 2018 Share Posted December 7, 2018 Ah, shoot! Thanks for reporting! Link to comment Share on other sites More sharing options...
Recommended Posts