| | |
Inserting data to a mysql table problems :(
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Mar 2008
Posts: 7
Reputation:
Solved Threads: 0
Hey all, first post here and im also very new to PHP, but been having major headaches over one query.
The query simply inserts some data into a table, which i've done in myphpadmin, the myphpadmin looks like this:
Registration_ID int(10) No auto_increment
Registration_Date date No
Academic_Year int(2) No
Year_of_Study int(2) No
Resit_exam int(5) No
Student_ID int(9) No
Module_ID varchar(10) latin1_swedish_ci No
(The no's being: NOT NULL)..
However on inserting the data into a query (Echo'ing the sql query with some valid data.. I get the following):
INSERT INTO Registration (Registration_ID, Registration_Date, Academic_Year, Year_of_Study, Resit_exam, Student_ID, Module_ID) VALUES ('200000', '2007-01-01', '02', '02', '1' '200038989', 'COMP222')Error, insert query failed
-- On the form, I hid the reg id field, and have tried it with a value, and without, and im getting to the same stage, I tried manually inputting the data above via myphpadmin and it worked completely fine.. So im at a loss to whats wrong. The form obviously works fine, as it shows all the correct data thats input, even from the dropdown lists, and the radio button, all the names match up correctly.
Heres some of the code, including the query itself...
Any advice would be greatly appreciated, I've added things to different tables in same style without problems, just seem to be having big problems when an autonumber is involved, which I would want to self-increment, without the user involvement..
Cheers Ben.
The query simply inserts some data into a table, which i've done in myphpadmin, the myphpadmin looks like this:
Registration_ID int(10) No auto_increment
Registration_Date date No
Academic_Year int(2) No
Year_of_Study int(2) No
Resit_exam int(5) No
Student_ID int(9) No
Module_ID varchar(10) latin1_swedish_ci No
(The no's being: NOT NULL)..
However on inserting the data into a query (Echo'ing the sql query with some valid data.. I get the following):
INSERT INTO Registration (Registration_ID, Registration_Date, Academic_Year, Year_of_Study, Resit_exam, Student_ID, Module_ID) VALUES ('200000', '2007-01-01', '02', '02', '1' '200038989', 'COMP222')Error, insert query failed
-- On the form, I hid the reg id field, and have tried it with a value, and without, and im getting to the same stage, I tried manually inputting the data above via myphpadmin and it worked completely fine.. So im at a loss to whats wrong. The form obviously works fine, as it shows all the correct data thats input, even from the dropdown lists, and the radio button, all the names match up correctly.
Heres some of the code, including the query itself...
PHP Syntax (Toggle Plain Text)
$Registration_ID=$_POST['Registration_ID']; // Set all variables as the input by the form $Registration_Date=$_POST['Registration_Date']; $Academic_Year=$_POST['Academic_Year']; $Year_of_Study=$_POST['Year_of_Study']; $Resit_exam=$_POST['Resit_exam']; $Student_ID=$_POST['Student_ID']; $Module_ID=$_POST['Module_ID']; //query to insert the relevant data $query = "INSERT INTO Registration (Registration_ID, Registration_Date, Academic_Year, Year_of_Study, Resit_exam, Student_ID, Module_ID) VALUES ('$Registration_ID', '$Registration_Date', '$Academic_Year', '$Year_of_Study', '$Resit_exam' '$Student_ID', '$Module_ID')"; echo $query; mysql_query($query) or die('Error, insert query failed'); // run the query
Any advice would be greatly appreciated, I've added things to different tables in same style without problems, just seem to be having big problems when an autonumber is involved, which I would want to self-increment, without the user involvement..
Cheers Ben.
•
•
Join Date: Mar 2008
Posts: 154
Reputation:
Solved Threads: 19
You shouldn't be trying to insert a Registration_ID since its an auto_increment column.
Its a good habit to use mysql_error() so you can see the actual error:
Matti Ressler
Suomedia
Its a good habit to use mysql_error() so you can see the actual error:
PHP Syntax (Toggle Plain Text)
mysql_query($query) or die(mysql_error());
Matti Ressler
Suomedia
If you want your dreams to come true, the first thing you must do is to wake up....
Suomedia - Dynamic Content Management
Suomedia - Dynamic Content Management
you must not write values in inserting a field if it is auto increment.Just leave it blank and mysql will handle it for you.
php Syntax (Toggle Plain Text)
$query = "INSERT INTO Registration (Registration_ID, Registration_Date, Academic_Year, Year_of_Study, Resit_exam, Student_ID, Module_ID) VALUES ('', '$Registration_Date', '$Academic_Year', '$Year_of_Study', '$Resit_exam' '$Student_ID', '$Module_ID')";
Last edited by ryan_vietnow; Mar 18th, 2008 at 8:44 pm.
![]() |
Similar Threads
- Apache (Linux Servers and Apache)
- Problems in inserting data into MySQL table from JSP.... (JSP)
Other Threads in the PHP Forum
- Previous Thread: password validation
- Next Thread: pass the javascript variable to php page
| Thread Tools | Search this Thread |
ajax apache api array beginner beneath binary broadband broken button cakephp checkbox class cms code countingeverycharactersfromastring crack cron curl database date decode display dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail match md5 menu mlm multiple mysql mysql_real_escape_string oop paypal pdf php problem protocol query radio random recursion regex remote script search server session sessions sms smtp soap source space sql strip_tags survey syntax system table tutorial undefined update upload url validator variable video virus votedown web window.onbeforeunload=closeme; xml youtube






After removing the $Registration FROM THE VALUES to be added, and also the Registration_ID from the insert into, it all worked fine