SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP MySQL Error INSERT and UPDATE

    Hello, i have a problem that i could use some guidance on if possible.

    The code below throws this error at me :

    Notice: Query failed: 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 '1' at line 1 SQL: 1 in /home/******/public_html/DsV2/Database/MySQL.php on line 113


    PHP Code:
                // Copy the data from Signup to User table
                
    $sql="INSERT INTO ".USER_TABLE." SET
                        "
    .USER_TABLE_LOGIN."='".mysql_escape_string($row[USER_TABLE_LOGIN])."',
                        "
    .USER_TABLE_PASSW."='".mysql_escape_string($row[USER_TABLE_PASSW])."',
                        "
    .USER_TABLE_EMAIL."='".mysql_escape_string($row[USER_TABLE_EMAIL])."',
                        "
    .USER_TABLE_SIGN."='".mysql_escape_string($row[USER_TABLE_SIGN])."',
                        "
    .USER_TABLE_PREFIX."='".mysql_escape_string($row[USER_TABLE_PREFIX])."',
                                            "
    .USER_TABLE_POINTS."='".mysql_escape_string($row[USER_TABLE_POINTS])."',
                        "
    .USER_TABLE_REC."='".mysql_escape_string($row[USER_TABLE_REC])."',
                        "
    .USER_TABLE_LOC."='".mysql_escape_string($row[USER_TABLE_LOC])."',
                        "
    .USER_TABLE_WEB."='".mysql_escape_string($row[USER_TABLE_WEB])."',
                        "
    .USER_TABLE_MSN."='".mysql_escape_string($row[USER_TABLE_MSN])."',
                        "
    .USER_TABLE_YAH."='".mysql_escape_string($row[USER_TABLE_YAH])."',
                                            "
    .USER_TABLE_XFIRE."='".mysql_escape_string($row[USER_TABLE_XFIRE])."',
                        "
    .USER_TABLE_AVA."='".mysql_escape_string($row[USER_TABLE_AVA])."',
                        "
    .USER_TABLE_MAIN."='".mysql_escape_string($row[USER_TABLE_MAIN])."',
                        "
    .USER_TABLE_MON."='".mysql_escape_string($row[USER_TABLE_MON])."',
                        "
    .USER_TABLE_PROC."='".mysql_escape_string($row[USER_TABLE_PROC])."',
                        "
    .USER_TABLE_GRAP."='".mysql_escape_string($row[USER_TABLE_GRAP])."',
                                            "
    .USER_TABLE_RAM."='".mysql_escape_string($row[USER_TABLE_RAM])."',
                        "
    .USER_TABLE_SOUND."='".mysql_escape_string($row[USER_TABLE_SOUND])."'";
                
    // Add points to recruiters account
                
    $sql2="UPDATE ".USER_TABLE." SET points=points+'50' WHERE user_id=".mysql_escape_string($row[USER_TABLE_REC])."";
                
    $result=$this->db->query($sql and $sql2);
                if ( 
    $result->isError() ) {
                   return 
    FALSE
    I have tested the SQL's individually and they both work fine on there own but when i try and process them at the same time the above error occurs.

    Any ideas as to why?

    Thanks for any help in advance.

  2. #2
    SitePoint Wizard cmuench's Avatar
    Join Date
    Jul 2005
    Location
    At my computer
    Posts
    2,251
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    stick the following before your $result line
    PHP Code:
    echo $sql1;
    echo 
    $sql2

  3. #3
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,077
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    AFAIK MySQL will not let you execute two queries at the same time. You could rework the two so that one of them is a sub-query of the other.
    Last edited by SpacePhoenix; Oct 4, 2009 at 23:29. Reason: typo
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  4. #4
    SitePoint Addict SirAdrian's Avatar
    Join Date
    Jul 2005
    Location
    Kelowna, BC
    Posts
    289
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Even if you could (you can, I know at least MySQLi has some relevant functions), you would need to separate them with a semicolon and pass them in the same string. Your current syntax is majorly flawed:

    PHP Code:
    $result=$this->db->query($sql and $sql2); 
    $sql and $sql2 is evaluated as a single expression, which ends up being the boolean true. The boolean true then gets casted to the string "1" and that's what your database is seeing.

    My advice is to just execute two different queries.
    Adrian Schneider - Web Developer

  5. #5
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,350
    Mentioned
    63 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by SpacePhoenix View Post
    AFAIK MySQL will not let you execute two queries at the same time.
    yes, it does, although how you arrange to have them received and executed "at the same time" is the tricky part

    you could also send them together, one after the other, separated by a semi-colon -- this is easy enough to test in a front end app (e.g. phpmyadmin) except that what you don't see is that the front end app sends them one after the other

    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  6. #6
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,077
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by r937 View Post
    yes, it does, although how you arrange to have them received and executed "at the same time" is the tricky part

    you could also send them together, one after the other, separated by a semi-colon -- this is easy enough to test in a front end app (e.g. phpmyadmin) except that what you don't see is that the front end app sends them one after the other

    Just to add to that from something I just looked up:

    mysql_ query function can't run two querires at the same time
    mysqli_ query function can run two quries at the same time
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  7. #7
    SitePoint Addict SirAdrian's Avatar
    Join Date
    Jul 2005
    Location
    Kelowna, BC
    Posts
    289
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No... it should only able to execute one.

    mysqli_multi_query on the other hand can handle many at once.
    Adrian Schneider - Web Developer

  8. #8
    SitePoint Member
    Join Date
    Sep 2009
    Posts
    13
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help guys,

    This done the trick :

    PHP Code:
                    $result $db->query($sql);
                    
    $result $db->query($sql2); 


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
  •