Jump to content

[SOLVED] Multiple checkbox query part 2 - error message!


greencoin

Recommended Posts

Looks like I closed the other post too soon. Here's my code:

Page1

<?
<form method="POST" action="track_area_results.php">
Select the states to search
  <table width="500" border="0" cellspacing="0" cellpadding="0">
    <tr>
      <td><input type="checkbox" name="state[]" value="ak">
        AK</td>
etc etc... ?>

 

Page2:

<?php
$name2 = $_POST['name2'];
for($name2array=0; $name2array < sizeof($name2); $name2array++)
{
if($name2array < (sizeof($name2)-1)) { $name2_cond = " OR "; }
else { $name2_cond = ""; }
$name2q = $name2q."`name2` LIKE'".$name2[$name2array]."'$name2_cond"; // I'm thinking this is the problem code
}
$name2q = "($name2q)";
$query = "SELECT * FROM GC_Tracker WHERE $name2q"; // I'm assuming this is the line one referenced in the error
                                                                             // as the only code on line one is the mysql_connect
                                                                             // function which I know is working.
$result = mysql_query($query) or die(mysql_error());
   
    if ($result = mysql_query($sql)) {
etc etc... 
?>

Which kicked out an error: "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ')' at line 1"

 

I'm a n00b and don't know the first thing about coding variations in MySQL versions and syntax erros drive me nuts! My MySQL is version 4.1 hosted by Godaddy. Anyone see anything the matter? Thanks again ~Rich

Link to comment
Share on other sites

OK OK - I checked a little closer and found that my checkbox string did not match what my $_POST[] was looking for so I changed it and now it tells me :

 

Query failed

 

Query was empty

 

I'm going to double check my table but I'm quite certain that field is full. Any tips on troubleshooting the problem? ~Rich

 

btw, I posted this before I read what thorpe had posted

Link to comment
Share on other sites

Very nice. Here's what I got with a single checkbox checked;

 

SELECT * FROM GC_Tracker WHERE (`area` LIKE'ak')

 

And with 2 checked;

 

SELECT * FROM GC_Tracker WHERE (`area` LIKE'ak' OR `area` LIKE'la')

 

Does this look right for MySQL 4.1? Aren't the single quotes supposed to be double quotes? ~Rich

Link to comment
Share on other sites

OK - so I modified the code to;

<?php
$name2q = $name2q."\"area\" LIKE'".$name2[$name2array]."'$name2_cond"; // put area in doubles quotes
}
$name2q = "($name2q)";
$query = "SELECT * FROM GC_Tracker WHERE $name2q";?>

 

 

which gives me the correct query output of;

"SELECT * FROM GC_Tracker WHERE ("area" LIKE'ak')

 

but it's still telling me the query failed, query was empty. I know the table has the info.. I tried a query with all 50 boxes checked, tried a query with one box checked (with a known matching record). I am now "officially" totally lost.  ??? Anyone? ~Rich

 

Link to comment
Share on other sites

OK again, figured out what I was doing wrong to cause the "Query was empty"

 

<?php
$result = mysql_query($query) or die(mysql_error()); \\ changed $result to $sql
   
if ($result = mysql_query($sql)) \\ there is no $sql variable defined!! 
?>

 

Ahh, the joy of recycling code. Now I have a different error with a much more ominous error message that I'm going to post in a new thread. Thanks for the help Thorpe. Case closed! ~Rich

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.