0

I have 2 accounts with the same hosting company but on different servers. I have been using this code on both for different data for some time. The data comes from a webform. MySQL was updated recently on one of the servers and the code stopped working. event_id field is set to auto-increment

$query = "INSERT INTO table (event_id, event_date, event_time, event_title, event_code, event_content) VALUES ('', '$event_date', '$event_time', '$event_title', '$event_code', '$event_content')";

I changed the code by removing the event_id from the first line and '', from the second as below and it now works

$query = "INSERT INTO table (event_date, event_time, event_title, event_code, event_content) VALUES ('$event_date', '$event_time', '$event_title', '$event_code', '$event_content')";

I really want to ask whether this is the effect of the MySQL upgrade or something else. I don't really know about coding so it is all trial and error using bits that have been written for me.

Margaret

3
  • Not part of your question, but your code is very dangerous. It has what is called an SQL injection vulnerability. Commented Dec 14, 2014 at 17:44
  • Thank you, Daniel, for pointing this out. We have added 'mysql_real_escape_string' into the code which I hope is the correct thing to do. Margaret Commented Dec 18, 2014 at 17:40
  • That is the start of the correct thing. The "best" approach is to use prepared statements and the a modern client code (mysqli or PDO MySQL) Commented Dec 18, 2014 at 21:35

1 Answer 1

0

The answer is simple: you cannot set a value to auto-increment field :)

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

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.