0

I'm receiving the following error code when trying to "Add a New Student" to MySQL database scheduler program:

Invalid query:

INSERT INTO student(student_id, name, password, number_paid_lessons, paid_from_date, paid_until_date) VALUES('DEFAULT', 'Test Student', 'Test Password', 12, '2014-1-01', '2014-3-31')

Incorrect integer value: 'DEFAULT' for column 'student_id' at row 1

The tech staff at my hosting company explained: "Means that the incorrect mysql value is DEFAULT into row student_id."

Coding is in php...How to fix? Do I just need to change the insert.php page code...or...the student.php page code? If so, to what?

John Conde
  • 217,595
  • 99
  • 455
  • 496
wmc531
  • 11
  • 1

3 Answers3

3

Don't pass 'DEFAULT'. Just leave that column out of your column list and values list, and the default will get inserted automatically.

elixenide
  • 44,308
  • 16
  • 74
  • 100
1

Assuming your student_id column has a set default value you do not need to specify it in your query for the default value to be applied.

INSERT INTO student(name, password, number_paid_lessons, paid_from_date, paid_until_date) 
VALUES('Test Student', 'Test Password', 12, '2014-1-01', '2014-3-31')
John Conde
  • 217,595
  • 99
  • 455
  • 496
0

If student_id is an autoincrement field, just leave it empty

INSERT INTO student(student_id, name, password, number_paid_lessons, paid_from_date, paid_until_date) 
VALUES('', 'Test Student', 'Test Password', 12, '2014-1-01', '2014-3-31')

Else, give a number instead of default

INSERT INTO student(student_id, name, password, number_paid_lessons, paid_from_date, paid_until_date) 
VALUES(1, 'Test Student', 'Test Password', 12, '2014-1-01', '2014-3-31')
Mario Radomanana
  • 1,698
  • 1
  • 21
  • 31