SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 48
  1. #1
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    You have an error in your SQL syntax

    This script displays and updates content from a table. However when i hit submit i get the error:

    You have an error in your SQL syntax near '' at line 1

    PHP Code:
    <?
    mysql_pconnect
    ("localhost","user","pass");
    mysql_select_db("xxx");
    ?>
    <HTML>
    <HEAD>
    <TITLE>Untitled Document</TITLE>
    <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
    </HEAD>

    <BODY BGCOLOR="#FFFFFF" TEXT="#000000">
    <? 
        
    if( $HTTP_POST_VARS["submit"] ) {
        
    $name trim$HTTP_POST_VARS["name"] );
        
    $tone trim$HTTP_POST_VARS["tone"] );
        
    $tempo trim$HTTP_POST_VARS["tempo"] );
        
    $cat trim$HTTP_POST_VARS["cat"] );
        
    $tone addslashes($tone);
        
    mysql_query"UPDATE tones SET name='$name', tone='$tone', tempo='$tempo', cat='$cat' WHERE id=$id
        or die( 
    mysql_error() ); 
        } 
    ?> 

    <? 
        $result 
    mysql_query"SELECT * FROM tones WHERE id=$id) or die( mysql_error() );
        
    $myrow mysql_fetch_array$result ) or die( mysql_error() );
        
    $name $myrow["name"];
        
    $tone $myrow["tone"]; 
        
    $tempo $myrow["tempo"]; 
        
    $cat $myrow["cat"]; 
    ?>

    <form method="post" action="<? {echo "$PHP_SELF";} ?>">

    <TABLE WIDTH="100%" BORDER="0" CELLSPACING="0" CELLPADDING="0">

    <TR> 
    <TD WIDTH="6%">cat</TD>

    <TD WIDTH="94%"> 

    <SELECT NAME='cat'>
    <OPTION VALUE="<? print( $cat ); ?>" SELECTED> 
    <? print( $cat ); ?>
    </OPTION>
    <OPTION VALUE='new'>new 
    </SELECT>

    </TD>

    </TR>

    <TR> 
    <TD WIDTH="6%">tempo</TD>
    <TD WIDTH="94%"> 
    <SELECT NAME='tempo'>
    <OPTION VALUE="<? print( $tempo ); ?>" SELECTED> 
    <? print( $tempo ); ?>
    </OPTION>
    <OPTION VALUE='140'>140 
    </SELECT>

    </TD>

    </TR>

    <TR> 

    <TD WIDTH="6%"> title:</TD>

    <TD WIDTH="94%">

    <INPUT TYPE="Text" NAME="name" VALUE="<? print( $name ); ?>">

    </TD>

    </TR>
    <TR>

    <TD WIDTH="6%">article:</TD>
    <TD WIDTH="94%">

    <TEXTAREA NAME='tone' ROWS="20" COLS="50"><? print( $tone ); ?></TEXTAREA>

    </TD>
    </TR>
    </TABLE>

    <input type="Submit" name="submit" value="Enter information">

    </form> 

    </BODY>
    </HTML>
    any ideas?
    Last edited by redgoals; Mar 5, 2002 at 16:34.
    http://redgoals.com ... my site ... nuff said

  2. #2
    SitePoint Addict
    Join Date
    Nov 2001
    Location
    Dublin, Ireland
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: You have an error in your SQL syntax

    PHP Code:
    <? 
        $result 
    mysql_query"SELECT * FROM tones WHERE id=" $id ) or die( mysql_error() );
    ?>

    You didn't close the tag you opened for the WHERE id=" part. The code should be:

    PHP Code:
    <? 
        $result 
    mysql_query"SELECT * FROM tones WHERE id=$id) or die( mysql_error() );
    ?>
    Don't worry, the ID will be passed as whatever it is and not $id because PHP and MySQL parse everything between "".

  3. #3
    SitePoint Addict
    Join Date
    Nov 2001
    Location
    Dublin, Ireland
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Bwa ha! A reply within 5 minutes, SitePoint rules!

  4. #4
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no luck, same error.
    http://redgoals.com ... my site ... nuff said

  5. #5
    SitePoint Addict
    Join Date
    Nov 2001
    Location
    Dublin, Ireland
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Aww crap.

    Why can't vB number lines god dammit! Anyway, lemme take a look at the rest of the code, that was the first error I spotted.

  6. #6
    SitePoint Addict
    Join Date
    Nov 2001
    Location
    Dublin, Ireland
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It may be that your host does not support persistant MySQL connections and that would produce an error in mysql_pconnect(); which seems to be line 1 ...

  7. #7
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i use that method on 2 other similar scripts but get no errors.
    http://redgoals.com ... my site ... nuff said

  8. #8
    SitePoint Addict
    Join Date
    Nov 2001
    Location
    Dublin, Ireland
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well we can rule that out I guess, hmmm ... this is a tough one. Is that the only error message you are getting?

  9. #9
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok just tried mysql_connect method, no luck their either.

    thats the only error messge i get after the page submits, no ugly mysql error.
    http://redgoals.com ... my site ... nuff said

  10. #10
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Echo your queries before you run them! Probably the best way to find these errors by far!

  11. #11
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the record does display using the select query.

    Its just this error that i get after the record is submitted.
    http://redgoals.com ... my site ... nuff said

  12. #12
    SitePoint Addict
    Join Date
    Nov 2001
    Location
    Dublin, Ireland
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quinn, what did I tell you about staying off my patch in this thread?

    His advice is sound though ...

  13. #13
    SitePoint Addict
    Join Date
    Nov 2001
    Location
    Dublin, Ireland
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So, the info is being added to the database and all the MySQL stuff is working?

    Unless mysql_pconnect() is necessary, try it with mysql_connect() and see if it works ...

  14. #14
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok this is beggining to drift into one of those weird unexplained cases.

    i just echoed the result before the record is updated and the data has changed to what i changed it to.

    So i thought everything was fine, mind i still got that error. However the record has not changed in table when i went to check it.
    http://redgoals.com ... my site ... nuff said

  15. #15
    SitePoint Addict
    Join Date
    Nov 2001
    Location
    Dublin, Ireland
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So, we can assume it's a problem with your UPDATE query ... out of curiosity, what version of MySQL are you using?

  16. #16
    SitePoint Addict
    Join Date
    Nov 2001
    Location
    Dublin, Ireland
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    JESUS! IT IS SO OBVIOUS! We are all idiots.

    You are using UPDATE ..... WHERE id=$id but $id has not been defined ... Sort that out and all should be okay.

  17. #17
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    3.23.37
    http://redgoals.com ... my site ... nuff said

  18. #18
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    id is defined in url string.
    http://redgoals.com ... my site ... nuff said

  19. #19
    SitePoint Addict
    Join Date
    Nov 2001
    Location
    Dublin, Ireland
    Posts
    313
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Aww damn! Anyway, I'll be back in an hour or so ... in the mean time I will leave you in the capable hands of the other SitePoint'ers.

  20. #20
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok thanks for the help anyway mate.
    http://redgoals.com ... my site ... nuff said

  21. #21
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So the problem now lies with your UPDATE query? Try echoing that and post what ya get here.

  22. #22
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    tried that already, i get the new values that were placed in the form, but i also get that annoying error, and the record is not updated.
    http://redgoals.com ... my site ... nuff said

  23. #23
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You still get the SQL syntax error? Can you post the SQL query here?

  24. #24
    And your point is.... redgoals's Avatar
    Join Date
    Feb 2002
    Location
    Birmingham, UK
    Posts
    496
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i posted it a the top, but here it is:

    PHP Code:
    mysql_query"UPDATE tones SET name='$name', tone='$tone', tempo='$tempo', cat='$cat' WHERE id=$id) or die( mysql_error() ); 

    just a side note, how come it says your offline in the left hand column?.
    http://redgoals.com ... my site ... nuff said

  25. #25
    SitePoint Wizard
    Join Date
    Jul 1999
    Location
    Chicago
    Posts
    2,629
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, I meant for you to do this:

    PHP Code:

    $query 
    "UPDATE tones SET name='$name', tone='$tone', tempo='$tempo', cat='$cat' WHERE id=$id";
    echo 
    $query;
    mysql_query$query ) or die( mysql_error() ); 
    And then tell me what's echoed.

    Response to the side note: It's because I marked myself as invisible in my forum options. I forget why I did it, but thanks for reminding me to set it to visible again!


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
  •