Page 1 of 1

mysql syntax error

Posted: Fri Nov 01, 2002 5:05 pm
by jamal
Hi can anyone tell me why i am having an error in this code.
The error is mysql_fetch_array(): supplied argument is not a valid MySQL result resource.
Thanks



<html>
<body>





Code: Select all

mysql_connect ("localhost","myusername","mypass");
   
mysql_select_db ("aboutDB");

if ($first_name == "")
{$first_name = '%';}

if ($last_name == "")
{$last_name = '%';}

$result = mysql_query ("SELECT * FROM abouttbl
                         WHERE first_name LIKE '$first_name%'
                         AND last_name LIKE '$last_name%'
                       ");

if ($row = mysql_fetch_array($result)) {

do {
  print $row&#1111;"first_name"];
  print (" ");
  print $row&#1111;"last_name"];
  print ("&lt;p&gt;");
} while($row = mysql_fetch_array($result));

} else {print "Sorry, no records were found!";}

</body>
</html>
I have tried this also but it did not work.

Code: Select all

if (mysql_numrows($result) &gt; 0) {

do {
  print $row&#1111;"first_name"];
  print (" ");
  print $row&#1111;"last_name"];
  print ("&lt;p&gt;");
} while($row = mysql_fetch_array($result));

} else {print "Sorry, no records were found!";}

Posted: Fri Nov 01, 2002 5:48 pm
by mydimension
there must be a problem with your query, like one of the variables does not contain a value. try this and show us what you see:

Code: Select all

$quesry = "SELECT * FROM abouttbl
                         WHERE first_name LIKE '$first_name%'
                         AND last_name LIKE '$last_name%'"
$result = mysql_query ($query); 
print $quesry;

Posted: Fri Nov 01, 2002 6:56 pm
by volka
or

Code: Select all

$query = "SELECT * FROM abouttbl
                         WHERE first_name LIKE '$first_name%'
                         AND last_name LIKE '$last_name%'"
$result = mysql_query($query) or die($query.' :'.mysql_error()); 
print $query;
to see mysql's problem with the query

mysql_numrows

Posted: Fri Nov 01, 2002 6:59 pm
by phpScott
your have a lttle syntax error.
In your second attempt your use mysql_numrows to see if there is a result.
Try using mysql_num_rows instead.

phpScott

Posted: Mon Nov 04, 2002 2:23 am
by twigletmac
Hi can anyone tell me why i am having an error in this code.
It would have made it easier for everybody to help you if you actually said what the error was.

Mac