SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member gymahz's Avatar
    Join Date
    Feb 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question why is the query empty?

    hi,
    i am new to this forum and need help with my php. I am doing my project using PHP and kinda new to it.

    anyway, i was running this query, but its not working. I need to have a query that take involve values from checkboxes and i did this.

    for example in my html:

    HTML Code:
          <tr class="others">
    
            <td height="21">Skills Required: </td>
            <td width="215"> </td>
            <td width="30"></td>
            <td width="221"></td>
            <td width="135">&nbsp;</td>
            <td width="6">&nbsp;</td>
          </tr>
          <tr class="others">
    
            <td height="21">&nbsp;</td>
            <td colspan="5" valign="top"><table width="500" border="0">
    <tr>
    <td><input type="checkbox" name="checkbox[]" value="1">Drums</td>
    <td><input type="checkbox" name="checkbox[]" value="2">Piano</td>
    <td><input type="checkbox" name="checkbox[]" value="3">Harp</tr>
    <tr><td><input type="checkbox" name="checkbox[]" value="4">Harmonica</td>
    <td><input type="checkbox" name="checkbox[]" value="5">Bassoon</td>
    <td><input type="checkbox" name="checkbox[]" value="6">Oboe</tr>
    
    <tr><td><input type="checkbox" name="checkbox[]" value="7">Serpent</td>
    <td><input type="checkbox" name="checkbox[]" value="8">Clarinet</td>
    <td><input type="checkbox" name="checkbox[]" value="9">Guitar</tr>
    <tr><td><input type="checkbox" name="checkbox[]" value="10">Mandolin</td>
    <td><input type="checkbox" name="checkbox[]" value="11">Flute</td>
    <td><input type="checkbox" name="checkbox[]" value="12">Violin</tr>
    <tr><td><input type="checkbox" name="checkbox[]" value="13">Trombone</td>
    <td><input type="checkbox" name="checkbox[]" value="14">Trumpet</td>
    <td><input type="checkbox" name="checkbox[]" value="15">Tuba</tr>
    
    <tr><td><input type="checkbox" name="checkbox[]" value="16">Saxaphone</td>
    <td><input type="checkbox" name="checkbox[]" value="17">Singing</td>
    <td><input type="checkbox" name="checkbox[]" value="18">Cello</tr>
    <tr></table>
    </td>
    fyi... the checkbox are printed using php, extracted from database.

    so in my php, my piece of codes look like this:
    PHP Code:
    $query "Select CONCAT(FirstName,', ', LastName) AS Name, SkillName
    FROM Musician, Skills, Assets
    WHERE Musician.Pno = Assets.Pno
    AND Assets.Sno = Skills.Sno
    AND (Assets.Sno = "
    ;

    //takes the value out of the checkboxes that are ticked
    for($j =0$j<count($chk);$j++)
    {
    $query .= "$chk[$j] OR ";
    }

    //delete the last three character out of the $query
    $query substr($query0, -3);
    //close query
    $query .= ")";

    $result mysql_query($query) or die('Query failed: ' mysql_error() ); 
    this return an error message of Query failed: query was empty.
    I dun really know why....

    I did try to echo the $query, and it looks perfectly fine to me.

    The echoed result:

    Select CONCAT(FirstName,', ', LastName) AS Name, SkillName FROM Musician, Skills, Assets WHERE Musician.Pno = Assets.Pno AND Assets.Sno = Skills.Sno AND (Assets.Sno = 15 OR 17 )

    I did try to run the query in mysql and it works fine.

    My PHP is version 4.3.10-16 while mySQL is of versio 4.0.24.

    It would be great if anyone can point out my mistakes. Pwetty pwetty please.... Thanks in advance.

    Gymah

  2. #2
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Assets.Sno = 15 OR 17


    Try changing that to this:

    Assets.Sno=15 OR Assets.Sno=17

  3. #3
    SitePoint Member gymahz's Avatar
    Join Date
    Feb 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    $query .= "Assets.Sno = ";
    }

    $query = substr($query, 0, -17);

    did that by adding the above line... but it still gives back the same error.

  4. #4
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by gymahz

    $query = substr($query, 0, -17);
    Why are you doing this? That will strip off the last 17 characters, right?

    Have you echoed the query string after the call to substr()?

  5. #5
    SitePoint Member gymahz's Avatar
    Join Date
    Feb 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah.. i need to delete the 17 characters after the last loop, since i concatenate "Assets.Sno = " to the query

    PHP Code:
    for($j =0$j<count($chk);$j++)
                {
                    
    $query .= "$chk[$j] OR ";
                    
    $query .= "Assets.Sno = "

                }
                
                
    $query substr($query0, -17);
                
    $query .= ")";
                
                echo 
    $query"<br>"
    the echoed result,

    Select CONCAT(FirstName,', ', LastName) AS Name, SkillName FROM Musician, Skills, Assets WHERE Musician.Pno = Assets.Pno AND Assets.Sno = Skills.Sno AND (Assets.Sno = 1 OR Assets.Sno = 17)

    the query looks ok to me... still dont understand why it says the query is empty.

  6. #6
    Non-Member coo_t2's Avatar
    Join Date
    Feb 2003
    Location
    Dog Street
    Posts
    1,819
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by gymahz
    yeah.. i need to delete the 17 characters after the last loop, since i concatenate "Assets.Sno = " to the query
    Oh, I see.

    I don't know what could be causing it. I'd try running the query through some other means like Mysql Query Browser(graphical mysql client) and see if it works. I'd make sure I'm using the right foreign key names in my join, but I'm sure if that would give an "empty query" error.

  7. #7
    SitePoint Member gymahz's Avatar
    Join Date
    Feb 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    my bad... there's nothing wrong wif the query... just errr... some undeleted previous query line.... thanks for helping out tho!
    cheers!!


Bookmarks

Posting Permissions

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