0

I have following code written in PHP:

  $q = mysql_query("INSERT INTO logowania ('user','udane','ip') VALUES ($uid,0,'".ip()."')"); echo mysql_error();

Values of $uid and ip() are correct, you can trust me.

Structure of logowania table:

1   idlogowania     int(11)             

2   user    int(11) 

3   udane   tinyint(1)  

4   data    timestamp       on update CURRENT_TIMESTAMP     CURRENT_TIMESTAMP   ON UPDATE CURRENT_TIMESTAMP     

5   ip  text    utf8_polish_ci  

I don't know where is the error in the statement. MySQL gives:

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 ''user','udane','ip') VALUES (1,0,'79.184.7.44')' at line 1

I tried to debug that, but without successful ending. I know that could be very simple mistake, but human's vision isn't infallible...

2
  • Use mysqli_ function family (and prepared statements) instead of using obsolete mysql_ and building query "by hand". Commented Feb 22, 2014 at 20:42
  • @Vyktor I've used mysql_real_escape_string() function, before query. I'm sorry, but I hate mysqli_.... Commented Feb 22, 2014 at 20:47

3 Answers 3

1

Use back ticks for column name,otherwise they are treated as strings.

(`user`,`udane`,`ip`)
Sign up to request clarification or add additional context in comments.

1 Comment

You were first, so I will accept your answer :-). Now everything works. Thank you for help, that was a stupid error... :-(
1

Take out '' from the column names.

$q = mysql_query("INSERT INTO logowania ('user','udane','ip') VALUES ($uid,0,'".ip()."')"); echo mysql_error();

should be

$q = mysql_query("INSERT INTO logowania (user,udane,ip) VALUES ($uid,0,'".ip()."')"); echo mysql_error();

OR use back-tics for the col names

$q = mysql_query("INSERT INTO logowania (`user`,`udane`,`ip`) VALUES ($uid,0,'".ip()."')"); echo mysql_error();

1 Comment

You weren't first, but thanks for your help. Now everything works. Thank you for help, that was a stupid error... :-(
0

Alternative version:

$q = mysql_query("INSERT INTO logowania SET `user` = '" . $uid . "', `udane` = 0, `ip` = '" . ip() . "'"); echo mysql_error();

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.