Click here to Skip to main content
15,879,095 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i keep getting the same error i have looked through this website and many others trying to find a solution please can one of yous help me here is the code

please note on $link i have removed and replaced the hostnamem, username and password for security reasons

PHP
$link = mysqli_connect('****HOSTNAME*****', '***USERNAME****', '**PASSWORD**', 'a8834432_website')or die("cannot connect" . mysqli_connect_error());
$usr = $_POST['user'];
$pas = $_POST['pass'];
if ($usr == "")
{
header("Location: ../secure.php?error=E3");
die();
}
else if ($usr != "")
{
$result = mysqli_query($link, "SELECT * FROM 'website' WHERE 'user' = $usr");
//echo($result);

///////PROBLEM STARTS HERE ////////////

if (mysqli_num_rows($result) > 0) {
    // output data of each row
    while($row = mysqli_fetch_assoc($result)) {
        echo "id: " . $row["user"];
    }
}
}
?>
Posted
Updated 23-Feb-15 2:01am
v2
Comments
Peter Leow 23-Feb-15 10:55am    
$result is getting false instead of the recordset, something is wrong with the sql query.
Try this
SELECT * FROM `website` WHERE `user` = '$usr'
Member 11472678 23-Feb-15 10:59am    
hahar brilliant thank you so much for your winning solution peter !!!!

Try checking for errors using mysqli_connect_errno:
C#
$link = mysqli_connect('****HOSTNAME*****', '***USERNAME****', '**PASSWORD**', 'a8834432_website');
if (mysqli_connect_errno())
{
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
}


PS. Also free the result and the connection when done.
mysqli_free_result($result);
mysqli_close($link);


Good luck!
 
Share this answer
 
v2
Comments
Member 11472678 23-Feb-15 10:06am    
this didn't work its the problem stating at the
if (mysqli_num_rows($result) > 0)
thats what line the error is on and i cant get my head around it

thanks for your support
Member 11472678 23-Feb-15 10:14am    
iv changed it to
if ($result = $link->query("SELECT * FROM 'website' WHERE 'user' = $usr")) {

/* fetch associative array */
while ($row = $result->fetch_assoc()) {
echo ($row['user'] . $row['email']);
}
}

now im not getting a error nor a result
E.F. Nijboer 23-Feb-15 12:37pm    
Yes, now I also see in your original code in the question $result needed to be checked first before calling mysqli_num_rows($result), like this:
if ($result) {
if (mysqli_num_rows($result) > 0) {
...

But luckily you already found a solution :-)
Member 11472678 23-Feb-15 13:09pm    
i did thanks for your effort buddy iv been stressing for days over this and today iv made so much progress i think iv made up for the 2 days that iv been stressing haha :-)
E.F. Nijboer 23-Feb-15 14:08pm    
Next time you'll probably post the question after just an hour of sweating it yourself :-)
$result is getting false instead of the recordset, something is wrong with the sql query.
Try this
SELECT * FROM `website` WHERE `user` = '$usr'

You may use backticks, not quotes to enclose table or field identifiers, but it is only necessary with they are part of the mysql reserved words. So in this case, no backticks is fine.
 
Share this answer
 
Comments
Member 11472678 23-Feb-15 11:14am    
your comment suggestion has made it work thank you so much you dont know how much iv been stressing for days haha

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900