MySQL Select Statement Not Working
Posted: Wed Jan 26, 2011 5:28 pm
Hey guys,
The following PHP / MySQL code...
...produces this error...
The following PHP / MySQL code...
Code: Select all
<?php
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$connection = mysql_connect('localhost', 'username', 'password');
if (!$connection){
die('Cannot connect to MySQL: ' . mysql_error() . '.');
}
$select = mysql_select_db('database', $connection);
if (!$select){
die('Cannot select database: ' . mysql_error() . '.');
}
$query = mysql_query("SELECT * FROM table WHERE username = '$username'");
if (!$query){
die('Cannot execute SQL: ' . mysql_error() . '.');
}
while ($row = mysql_fetch_assoc($query)){
echo $row['username'] . '<br>';
echo $row ['password'];
}
?>Any ideas as how I can fix this?Cannot execute SQL: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'table WHERE username = ''' at line 1.