Web Analytics Made Easy -
StatCounter sql query problems - CodingForum

Announcement

Collapse
No announcement yet.

sql query problems

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • sql query problems

    I have created a html form page, and a corresponding process page.

    My form gets input from the user, and compares it to the fields in my database. If the input

    in the form matches a field in the dB, the process page returns the corresponding record.

    The problem is only the address input for the form works correctly. All of the other fields

    return all the records in the dB. I've tried varying the SQL query code many times.

    My question is why does only the address search work as opposed to the other input fields?

    search.php: form

    Code:
    <form id=\"search\" method=\"post\" action=\"process.php\">
    
    <table class=\"search1\">
    
    <tr>
    <th><label for=\"pad\">Pad Number</label></th>
    <td><input id=\"pad\" name=\"pad\" type=\"text\" class=\"inputbox\" size=\"50\" /><br 
    
    /></td>
    </tr>
    
    <tr>
    <th><label for=\"mls\">MLS Number</label></th>
    <td><input id=\"mls\" name=\"mls\" type=\"text\" class=\"inputbox\" size=\"50\" /><br 
    
    /></td>
    </tr>
    
    <tr>
    <th><label for=\"address1\">Address</label></th>
    <td><input id=\"address1\" name=\"address1\" type=\"text\" class=\"inputbox\" size=\"100\" 
    
    /><br /></td>
    </tr>
    
    <tr>
    <th><label for=\"city\">City</label></th>
    <td><input id=\"city\" name=\"city\" type=\"text\" class=\"inputbox\" size=\"100\" /><br 
    
    /></td>
    </tr>
    
    <tr>
    <th><label for=\"zip\">Zip Code</label></th>
    <td><input id=\"zip\" name=\"zip\" type=\"text\" class=\"inputbox\" size=\"15\" /><br 
    
    /></td>
    </tr>
    
    
    </table>
    
    <br />
    
    <table class=\"search2\">
    
    <tr>
    <td>
    
    <input type=\"Submit\" value=\"Submit\" style=\"width: 60px; font-size: 1.0em; padding: 2px 
    
    10px 2px 10px; margin: 5px 3px -3px 3px; background-color: #115492; float: left; border: 
    
    solid 1px #023666; color: #ffffff; text-decoration: none;\" />
    
    <input type=\"Reset\" value=\"Reset\" style=\"width: 60px; font-size: 1.0em; padding: 2px 
    
    10px 2px 10px; margin: 5px 3px -3px 3px; background-color: #115492; float: left; border: 
    
    solid 1px #023666; color: #ffffff; text-decoration: none;\" />
    
    <input type=\"hidden\" name=\"op\" value=\"do\" /><p>&nbsp;</p>
    </td>
    </tr>
    </form>
    
    </table>
    ---------------------------------------------
    process.php:

    Code:
    <? 
    # connect to a DSN "mydb" with a user and password "marin" 
    $connect = odbc_connect("**", "**", "**");
    
    # query the users table for name and surname
    $query = "SELECT * FROM props WHERE props.MLSnumber='$mls' 
    OR props.Pads LIKE '%$pad%'
    OR props.Address LIKE '%$address1%'
    OR props.City='$city'
    OR props.Zip='$zip'";
    
    # perform the query
    $result = odbc_exec($connect, $query);
    
    //output results to standard output 
    //odbc_result_all($result, "BORDER=1"); 
    
    # fetch the data from the database
    while(odbc_fetch_row($result)){
      $mls = odbc_result($result, 2);
      $address = odbc_result($result, 5);
      $pad = odbc_result($result, 16);
      $city = odbc_result($result, 7);
      $zip = odbc_result($result, 9);
      $check = odbc_result($result, 17);
    //  print("$mls  $address  $pad  $city  $zip");
      
      //format results 
        print ("<tr>"); 
        print ("<td>$pad</td>"); 
        print ("<td>$mls</td>"); 
        print ("<td>$address</td>"); 
    	print ("<td>$city</td>");
    	print ("<td>$zip</td>");
    	print ("</tr>"); 
        } 
    
    # close the connection
    odbc_close($connect);
    ?>

  • #2
    firsdt debugging action would be to put a
    PHP Code:
    echo $query
    in your code right before you execute the query --> so that you see what query is actually composed.
    my guess (based on the partial code) would be that you have register_globals set to off, and that you should replace $mls with $_POST['mls'] , $pad with $_POST['pad'] etc
    Posting guidelines I use to see if I will spend time to answer your question : http://www.catb.org/~esr/faqs/smart-questions.html

    Comment

    Working...
    X