0

Okay, i have this code

<?php
$email = htmlentities($_SESSION['user']['dato'], ENT_QUOTES, 'UTF-8');
$username = "mcnsaoia_onsafe";
$password = "XXX";
$hostname = "localhost"; 

//connection to the database
$dbhandle = mysql_connect($hostname, $username, $password) 
 or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";

//select a database to work with
$selected = mysql_select_db("mcnsaoia_onsafe",$dbhandle) 
  or die("Could not select examples");

//execute the SQL query and return records
$result = mysql_query("SELECT * FROM users WHERE id= '$email'") or die(mysql_error()); 

//fetch tha data from the database 
while($row = mysqli_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['status'] . "</td>";
  echo "<td>" . $row['email'] . "</td>";
  echo "</tr>";
  }
echo "</table>";
//close the connection
mysql_close($dbhandle);
?>

but when i run it, it just says Connected to MySQL and it DON'T output anything?? i have no idea why it does that?!

3
  • 1
    it is mysql_fetch_array not mysqli_fetch_array, BTW, use mysqli_* or PDO instead of using mysql_* functions(deprecated) Commented Feb 27, 2014 at 13:00
  • if don't work the comment above, please try use your sql this way: SELECT * FROM users WHERE id= Commented Feb 27, 2014 at 13:08
  • user mysqli_* instead of mysql extension, mysql extension is deprecated. Commented Feb 27, 2014 at 13:09

2 Answers 2

2
while($row = mysqli_fetch_array($result))

change it with mysql_fetch_array()

while($row = mysql_fetch_array($result))
Sign up to request clarification or add additional context in comments.

Comments

1

Check whether rows are returned by your query using mysql_num_rows() function.

if(mysql_num_rows($result)>1)
{
  while($row = mysql_fetch_array($result))
  {
  echo "<tr>";
  echo "<td>" . $row['status'] . "</td>";
  echo "<td>" . $row['email'] . "</td>";
  echo "</tr>";
  }
}
else
{
echo "No rows found";
}

Note : Use mysqli_* functions . mysql_* functions have been deprecated.

5 Comments

Okay.. is says No rows found, but I don't understand that? There is something at SELECT * FROM users ?!
are you sure you are comparing correct column .. WHERE id= '$email' ?
It works if I remove the where condition... but i NEED the where condition.. so i think it has something to do with the php variable? maybe
yes... print the variable and see if it value exist in table
$result = mysql_query("SELECT * FROM users WHERE email = '$email' ") or die(mysql_error()); work.. :-) thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.