Advanced Search

Results 1 to 10 of 10

Thread: error in my syntax

  1. #1
    Join Date
    Oct 2011
    Location
    London
    Posts
    41
    Thanks
    19
    Thanked 1 Time in 1 Post

    Unhappy error in my syntax

    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 'WHERE id = 4,' at line 1

    this is the error i get and this is what im using to get it
    Code:
    mysql_query("UPDATE data SET dischargetemp=$dischargetemp, condenceron=$condenceron, condenceroff=$condenceroff, leaktest=$leaktest, clean=$clean, saftey=$saftey, fan1=$fan1, fan2=$fan2, fan3=$fan3, notes=$notes, WHERE id = $_SESSION[id] ");
    any ideas...
    Last edited by TwitterRooms; 01-27-2012 at 04:54 PM.

  2. #2
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,122
    Thanks
    59
    Thanked 435 Times in 424 Posts
    Blog Entries
    7

    Default

    there shouldn't be a comma before your WHERE clause.
    Adrian ~ facebook | gist/github

    ['66.215.156.37','208.75.149.97'] // ip,ip array!
    "Take that sticker *off* your hat; you look stupid" --Wil Wheaton

  3. The Following User Says Thank You to traq For This Useful Post:

    TwitterRooms (01-23-2012)

  4. #3
    Join Date
    Oct 2011
    Location
    London
    Posts
    41
    Thanks
    19
    Thanked 1 Time in 1 Post

    Default

    thanks but even with the comma removed same error is there any whey to get more details of what it wrong with the WHERE clause

  5. #4
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,122
    Thanks
    59
    Thanked 435 Times in 424 Posts
    Blog Entries
    7

    Default

    could you post what the query looks like after php is done (what does mysql actually see)?
    Adrian ~ facebook | gist/github

    ['66.215.156.37','208.75.149.97'] // ip,ip array!
    "Take that sticker *off* your hat; you look stupid" --Wil Wheaton

  6. The Following User Says Thank You to traq For This Useful Post:

    TwitterRooms (01-24-2012)

  7. #5
    Join Date
    Oct 2011
    Location
    London
    Posts
    41
    Thanks
    19
    Thanked 1 Time in 1 Post

    Default

    ok i'm not shore what you mean but i have echo'ed all the $XXX in the query and they all have a value lets make it simple and try this

    Code:
    mysql_query("UPDATE data SET make=$make WHERE entryid=$_SESSION[id]");
    ive taken out all the verables till i get the basic code working then i add them back in with this code i get this 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

  8. #6
    Join Date
    Oct 2011
    Location
    London
    Posts
    41
    Thanks
    19
    Thanked 1 Time in 1 Post

    Default

    This is the whole file
    PHP Code:
    <?php
    session_start
    ();

    $con mysql_connect("XXXXXXXX","XXXXXXX","XXXXXX");
    if (!
    $con)
      {
      die(
    'Could not connect: ' mysql_error());
      }

    mysql_select_db("XXXXXXXXXX"$con);
    echo 
    mysql_error();
    function 
    clean($str) {
            
    $str = @trim($str);
            if(
    get_magic_quotes_gpc()) {
                
    $str stripslashes($str);
            }
            return 
    mysql_real_escape_string($str);
        }
    $make clean($_POST['make']);
    $model clean($_POST['model']);
    $serial clean($_POST['serial']);
    $comp1amps1 clean($_POST['comp1amps1']);
    $comp1amps2 clean($_POST['comp1amps2']);
    $comp1amps3 clean($_POST['comp1amps3']);
    $comp2amps1 clean($_POST['comp2amps1']);
    $comp2amps2 clean($_POST['comp2amps2']);
    $comp2amps3 clean($_POST['comp2amps3']);
    $suction clean($_POST['suction']);
    $discharge clean($_POST['discharge']);
    $suctiontemp clean($_POST['suctiontemp']);
    $dischargetemp clean($_POST['dischargetemp']);
    $condenceron clean($_POST['condenceron']);
    $condenceroff clean($_POST['condenceroff']);
    $leaktest clean($_POST['leaktest']);
    $clean clean($_POST['clean']);
    $saftey clean($_POST['saftey']);
    $fan1 clean($_POST['fan1']);
    $fan2 clean($_POST['fan2']);
    $fan3 clean($_POST['fan3']);
    $notes clean($_POST['notes']);


    mysql_query("UPDATE data SET make=$make, model=$model WHERE entryid=$_SESSION[id]");
    echo 
    mysql_error();
    //mysql_query("UPDATE data SET dischargetemp=$dischargetemp, condenceron=$condenceron, condenceroff=$condenceroff, leaktest=$leaktest, clean=$clean, saftey=$saftey, fan1=$fan1, fan2=$fan2, fan3=$fan3, notes=$notes, WHERE id = $_SESSION[id] ");


    //echo '<center><h2 style="color:white;">unit logged ID number is ', $_SESSION['id']; 
    //echo '</h2></center>
    //<link href="style.css" rel="stylesheet" type="text/css" />
    //<meta http-equiv="refresh" content="5; URL=index.php">
    //<span id="countdown" style="position:absolute;bottom:0px;left:5px;color:yellow;font-size:200%">5</span>        
    //    ';    
            
    ?>

  9. #7
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,122
    Thanks
    59
    Thanked 435 Times in 424 Posts
    Blog Entries
    7

    Default

    I'd need to see the string PHP outputs as the query. try replacing this:
    PHP Code:
    mysql_query("UPDATE data SET make=$make, model=$model WHERE entryid=$_SESSION[id]");
    echo 
    mysql_error(); 
    with this:
    PHP Code:
    $query "UPDATE data SET make=$make, model=$model WHERE entryid=$_SESSION[id]";
    print 
    $query;
    mysql_query$query );
    echo 
    mysql_error(); 
    and let me know what it prints.
    Adrian ~ facebook | gist/github

    ['66.215.156.37','208.75.149.97'] // ip,ip array!
    "Take that sticker *off* your hat; you look stupid" --Wil Wheaton

  10. The Following User Says Thank You to traq For This Useful Post:

    TwitterRooms (01-24-2012)

  11. #8
    Join Date
    Oct 2011
    Location
    London
    Posts
    41
    Thanks
    19
    Thanked 1 Time in 1 Post

    Default

    UPDATE data SET make=1, model=2 WHERE entryid=23Unknown column 'make' in 'field list'


    WHAT A COCK!!!!!! thank you for your help i feel very stupid now

  12. #9
    Join Date
    Oct 2011
    Location
    London
    Posts
    41
    Thanks
    19
    Thanked 1 Time in 1 Post

    Default

    ok i still have a problem
    PHP Code:
    $query "UPDATE data SET make=$make, model=$model WHERE entryid=$_SESSION[id]";
    print 
    $query;
    mysql_query$query );
    echo 
    mysql_error(); 
    works fine BUT when $make is a word it dont work cos it needs to be make='$make'
    how do i get round this

  13. #10
    Join Date
    Apr 2008
    Location
    So.Cal
    Posts
    3,122
    Thanks
    59
    Thanked 435 Times in 424 Posts
    Blog Entries
    7

    Default

    PHP Code:
    $query "UPDATE data SET make='$make', model='$model' WHERE entryid='$_SESSION[id]'"
    You don't have to worry about it that way - in fact, passing everything to MySQL as a string is fine because it prompts MySQL to do its own type conversion.
    Adrian ~ facebook | gist/github

    ['66.215.156.37','208.75.149.97'] // ip,ip array!
    "Take that sticker *off* your hat; you look stupid" --Wil Wheaton

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
  •