Why is my query not returning any results? I can run the query SELECT * FROMusersWHERE wid = 'worker_040' and it returns a result just fine. Am I missing something in this?
$wid = $_POST['username'];
$con = mysql_connect("11.88.3.2","XXXX","XXXXX");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("chit", $con);
echo "Form details<br />";
$result = mysql_query("SELECT * FROM `users` WHERE wid = '$wid'");
while($row = mysql_fetch_array($result)){
echo $row['FirstName']. " - ". $row['LastName'];
echo "<br />";
}
mysql_close($con);
$_POST['username']. Also, are you sure$widhas a value when you call the query? What does the completed SQL actually look like right before you callmysql_fetch_array()?echo $widand it outputs something like worker_040$resultvariable, put it in it's own$queryvariable then echo out the whole, complete SQL statement to ensure the entire thing matches against what works. As long as the ID exists in your DB I don't see why this shouldn't be returning results.mysql_error, and if there's no error in there, do avar_dump($wid);to check what is in there (do look at the source, not as an HTML page in a browser) (might be just a stray space that fouls things up for you).