Jump to content

Checking to see if the query ran


suttercain

Recommended Posts

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

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);

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();
  }

?>

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.