I'm trying to return a single record with the following statements:
$username = $_POST["username"];
$con=mysqli_connect("localhost","root","pass","Testproject");
// Check connection
if (mysqli_connect_errno($con))
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql = mysqli_query($con,"SELECT * FROM registeredusers where Username=".$username);
$row = mysqli_fetch_array($sql);
if (!$row) {
printf("Error: %s\n", mysqli_error($con));
exit();
}
and am getting the following errors:
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in "Filepath goes here"/AddEvent.php Error: Unknown column 'Tom' in 'where clause'
"Tom" in this case is the user name. Any ideas how to fix this? I've looked at similar questions on stackoverflow, but majority of them are a little more complex or aren't trying to get a single record.
EDIT: I've change the query to the following:
$sql = mysqli_query($con,"SELECT * FROM registeredusers") or die(mysqli_error($con));
$row = mysqli_fetch_array($sql);
And added this as well"
$row_cnt = $result->num_rows;
printf("Result set has %d rows.\n", $row_cnt);
Im getting the following:
"Result set has 0 rows".
I've typed the exact query into my DBMS and it returns many rows.
=". $row['username'] ."=
";) – p0ny Dec 14 '13 at 21:02