PHP MySQL Select Problem
Why is my query not returning any results? I can run the query SELECT * FROM
usersWHERE 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 />";
开发者_JAVA百科 }
mysql_close($con);
You could take some time to debug.
For example, make sure your script is accessed via an HTTP POST request and 'username' is sent in the request ($_POST['request'] is set and has a valid value which could/would return results).
Get some info after executing your queries (you could use mysql_error()), get the number of rows returned etc. Output your sql query before sending it for execution.
Print the value of each row in your while loop.
These are some hints/tips you could use for finding out what might be going on. There are also other ways but you could give the above a try.
You are calling your result rows as a numeric array but referencing them as an associative array - change your while
loop to use mysql_fetch_assoc
Edit - this probably isn't it!
mysql_fetch_array
returns the array as both an associative and numeric array by default, so shouldn't affect your code above.
精彩评论