suttercain Posted March 29, 2007 Share Posted March 29, 2007 Hello, I have the following code: function show_use($year,$man,$use) { //Result SQL statement $sql="SELECT * FROM " .$year. "data WHERE MFR = '" .$man. "' AND Use='" .$use. "'"; //Connect to server require_once ("connect.php"); //Count the number of results $result = mysql_query("SELECT * FROM " .$year. "data WHERE MFR = '" .$man. "' AND Use='" .$use. "'"); //$rows = mysql_result($result, 0, 'total'); $rows = mysql_num_rows($result); I tried to see if the query ran by using this code: if mysql_query($result == TRUE){ echo "The $result worked!"; } else echo "Nope the $result didn't work"; It didn't work. Where am I going wrong? Thanks. Link to comment https://forums.phpfreaks.com/topic/44844-checking-to-see-if-the-query-ran/ Share on other sites More sharing options...
shaunrigby Posted March 29, 2007 Share Posted March 29, 2007 if mysql_query($result == TRUE){ echo "The $result worked!"; } else { echo "Nope the $result didn't work"; } Plus why are you defining a variable with the query, but then typing the query out again? Why not put $result = mysql_query($sql); Link to comment https://forums.phpfreaks.com/topic/44844-checking-to-see-if-the-query-ran/#findComment-217778 Share on other sites More sharing options...
trq Posted March 29, 2007 Share Posted March 29, 2007 Im sure I showed you the correct syntax yesterday. <?php // connect. // $sql holds your query. if ($result = mysql_query($sql)) { if (mysql_num_rows($result)) { // display data. } else { echo "No records found"; } } else { echo "Query failed<br />$sql<br />" . mysql_error(); } ?> Link to comment https://forums.phpfreaks.com/topic/44844-checking-to-see-if-the-query-ran/#findComment-217786 Share on other sites More sharing options...
suttercain Posted March 29, 2007 Author Share Posted March 29, 2007 Hi Thorpe. Nope it wasn't me yesterday. But thanks. I tried the code and when I select the first dropdown it populates the second from the mysql. When I select the second dropdown it doesn't populate the third. I was trying to verify that the query was working. Thank you for the suggestions. I'll keep trying. Shannon Link to comment https://forums.phpfreaks.com/topic/44844-checking-to-see-if-the-query-ran/#findComment-217789 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.