0

I have a JavaScript calendar

<input type="text" size="8" id="date"  name="calendar[]" />

When I input the following php it disables the calendar.

$result=mysql_query("select * from products where id='maui'");
while($row=mysql_fetch_array($result)){

but if I input the php without the "where clause" it works:

$result=mysql_query("select * from products");
while($row=mysql_fetch_array($result)){

What are some options for a work around?

Tristan
  • 3,301
  • 8
  • 22
  • 27
leo9dis
  • 1
  • 1

1 Answers1

0

I would imagine there is either a syntax error in you query, or the id does not exist and therefore no results are returned. So always check the status of a database access call

$result=mysql_query("select * from products where id='maui'");
if ( $result === FALSE ) {
    echo mysql_error();
    exit;
}
if ( mysql_num_rows() == 0 ) {
    echo 'No results returned';
    exit;
}
while($row=mysql_fetch_array($result)){

Please dont use the mysql_ database extension, it is deprecated (gone for ever in PHP7) Especially if you are just learning PHP, spend your energies learning the PDO or mysqli_ database extensions, and here is some help to decide which to use

Community
  • 1
  • 1
RiggsFolly
  • 93,638
  • 21
  • 103
  • 149