www.webdeveloper.com
Results 1 to 6 of 6

Thread: PHP Radio buttons

  1. #1
    Join Date
    Feb 2012
    Posts
    19

    PHP Radio buttons

    Hi..I was looking for a sample using PHP with radio buttons to select queries from mysql. I found the following which I wanted to use for my own data. However I get the following error:

    Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/tdprout/public_html/halfwayenterprises.com/searchengine/inventory.php on line 22

    Here is the PHP

    <?php
    ob_start();
    require("config.php");
    ob_end_clean();



    $req=$_REQUEST['make'];
    $req2=$_REQUEST['availability'];

    mysql_connect("localhost",$username,$password);
    mysql_select_db($database) or die( "Unable to select database");

    if ($req!="all" && $req2!="all")
    $query=("SELECT * FROM 'cars' WHERE make='$req' AND availability='$req2'");
    else if($req=="all" && $req2!="all" ) $query=("SELECT * FROM 'cars' WHERE availability='$req2'");
    else if($req!="all" && $req2=="all" ) $query=("SELECT * FROM 'cars' WHERE make='$req'");
    else if($req=="all" || $req2=="all" ) $query=("SELECT * FROM 'cars'");

    $result = mysql_query($query);

    $num = mysql_num_rows($result);
    mysql_query($result);
    mysql_close();

    $i=0;

    for ($i; $i < $num; $i++){

    $f12=mysql_result($result,$i,"model");
    $f13=mysql_result($result,$i,"year");
    $f14=mysql_result($result,$i,"availability");

    echo $f12." ".$f13." ".$f14."<br />";
    }
    ?>

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,312
    That means your query could not be processed by MySQL. You should add some defensive code to help capture the debug data, e.g.:
    PHP Code:
    $result mysql_query($query);
    if(
    $result == false) {
      
    error_log(mysql_error().PHP_EOL.$query);
      die(
    "Sorry, there was a database error. Details have been logged.");

    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Mar 2012
    Posts
    21
    your missing

    mysql_query("SELECT * FROM

  4. #4
    Join Date
    Feb 2012
    Posts
    19
    Added both of the suggestions...now I get this error.... Sorry, there was a database error. Details have been logged.

  5. #5
    Join Date
    Feb 2011
    Posts
    231
    Hi,
    Remove the simple quotes from the name of the table. Use these character `...` (near key 1 on the keyboard), or simple, just the name. The same for column name.
    Code:
    $query="SELECT * FROM cars";

  6. #6
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,312
    Quote Originally Posted by tdp View Post
    Added both of the suggestions...now I get this error.... Sorry, there was a database error. Details have been logged.
    Which mean you should then inspect your PHP error log to find out what the actual problem was and what your query actually looked like when it was sent to MySQL. If you don't know where your PHP log is, then you can find it amidst all the stuff output by a call to phpinfo(). Or for debugging purposes only (you don't want this kind of info output on a live site), you can change the error_log() to an echo(), perhaps wrapping the output in "<pre>" tags.
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles