0

I have an error when I try to write to the database.

Error message (I tested it with some values...):

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 'values(Digger, 45_456, 645_645, 6_6, 456_456, 456_45, ' at line 3

My code:

Mysql_query("INSERT INTO 
        ".$balicky_table." 
        values(".$name.",     <-line 3
        ".$id1."_".$kus1.", 
        ".$id2."_".$kus2.", 
        ".$id3."_".$kus3.", 
        ".$id4."_".$kus4.", 
        ".$id5."_".$kus5.", 
        ".$id6."_".$kus6.", 
        ".$id7."_".$kus7.", 
        ".$id8."_".$kus8.", 
        ".$id9."_".$kus9.", 
        ".$id10."_".$kus10.", 
        ".$id11."_".$kus11.", 
        ".$id12."_".$kus12.", 
        ".$cost.")", $SpojenieWeb) or die(mysql_error());

In database I have type Varchar(100)

4
  • 1
    You need to wrap each value in quotes. That said, this code is open to SQL injection if any of those variables come from external sources. Commented Jun 8, 2013 at 12:29
  • For text data need use single quotes, like this values('".$name."', Commented Jun 8, 2013 at 12:30
  • Could you tell use what it stored in $balicky_table, you are missing quotes for sure but you also have an error before in columns Commented Jun 8, 2013 at 12:34
  • 1
    This all looks very, very wrong. Have you read up on normalization? Commented Jun 8, 2013 at 12:42

4 Answers 4

1

Digger is a string so needs quotes: values('".$name."',.

Sign up to request clarification or add additional context in comments.

3 Comments

Dont work I add quotes: 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 'values('Digger', 45_456, 645_645, 6_6, 456_456, 456_45,' at line 3
ok all values are quotes - dont work In database I have columns with varchar(110) And names are 1. name 2. Item_1 3. Item_2 ..... Item_12 and cost
I'd suggest updating your question accordingly, with the new error message.
0

You need quotes: see here:

Mysql_query("INSERT INTO 
        ".$balicky_table." 
        values('".$name."',    
        '".$id1."_".$kus1."', 
        '".$id2."_".$kus2."', 
        '".$id3."_".$kus3."', 
        '".$id4."_".$kus4."', 
        '".$id5."_".$kus5."', 
        '".$id6."_".$kus6."', 
        '".$id7."_".$kus7."', 
        ''".$id8."_".$kus8."', 
        '".$id9."_".$kus9."', 
        '".$id10."_".$kus10."', 
        '".$id11."_".$kus11."', 
        '".$id12."_".$kus12."', 
        '".$cost."')", $SpojenieWeb) or die(mysql_error());

Comments

0

You have to qoute the data. That is the problem

Check this:

"INSERT INTO 
    ".$balicky_table." 
    values('".$name."',
    '".$id1."_".$kus1."', 
    '".$id2."_".$kus2."', 
    '".$id3."_".$kus3."', 
    '".$id4."_".$kus4."', 
    '".$id5."_".$kus5."', 
    '".$id6."_".$kus6."', 
    '".$id7."_".$kus7."', 
    '".$id8."_".$kus8."', 
    '".$id9."_".$kus9."', 
    '".$id10."_".$kus10."', 
    '".$id11."_".$kus11."', 
    '".$id12."_".$kus12."', 
    '".$cost."')", $SpojenieWeb)

Comments

0

Hi it seems like the value over here are strings. As you concetnate them using '_' . String needs to be wrapped with quote. As you are using Double quote for your php you can wrap using single quote single quote.

"INSERT INTO 
  ".$balicky_table." 
  values('".$name."',
  '".$id1."_".$kus1."', 
  .......

For all of them.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.