timmah1 Posted January 16, 2008 Share Posted January 16, 2008 Can anyone tell me why this isn't working? <?php include ('DB_config.php'); mysql_query('DROP TABLE IF EXISTS `users`') or die(mysql_error()); mysql_query('CREATE TABLE IF NOT EXISTS `users` ( id int(11) NOT NULL auto_increment, date date NOT NULL default 0000-00-00 00:00:00, title varchar(255) NOT NULL default, name varchar(255) NOT NULL default, surname varchar(15) NOT NULL default , sex varchar(15) NOT NULL default, post varchar(15) NOT NULL default, mobile varchar(25) NOT NULL default, age varchar(25) NOT NULL default, transport varchar(255) NOT NULL default, file varchar(255) NOT NULL default, PRIMARY KEY(id))') or die(mysql_error()); ?> I keep getting this error 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 '-00-00 00:00:00, title varchar(255) NOT NULL default, name varchar(255) NOT ' at line 3 Thanks in advance Link to comment https://forums.phpfreaks.com/topic/86312-solved-mysql-insert-why-this-dont-work/ Share on other sites More sharing options...
trq Posted January 16, 2008 Share Posted January 16, 2008 `date` date NOT NULL default '0000-00-00 00:00:00', Link to comment https://forums.phpfreaks.com/topic/86312-solved-mysql-insert-why-this-dont-work/#findComment-440947 Share on other sites More sharing options...
revraz Posted January 16, 2008 Share Posted January 16, 2008 Don't use date as your field name. Link to comment https://forums.phpfreaks.com/topic/86312-solved-mysql-insert-why-this-dont-work/#findComment-440954 Share on other sites More sharing options...
timmah1 Posted January 16, 2008 Author Share Posted January 16, 2008 I changed date to signup instead Now I'm getting this Parse error: syntax error, unexpected T_LNUMBER in /home/celtic-teambuild/public_html/sign/install.php on line 9 Do I have to enclose every field name with a ` Link to comment https://forums.phpfreaks.com/topic/86312-solved-mysql-insert-why-this-dont-work/#findComment-440964 Share on other sites More sharing options...
revraz Posted January 16, 2008 Share Posted January 16, 2008 Only if it's a reserved word. What is line 8 & 9 Link to comment https://forums.phpfreaks.com/topic/86312-solved-mysql-insert-why-this-dont-work/#findComment-440969 Share on other sites More sharing options...
timmah1 Posted January 16, 2008 Author Share Posted January 16, 2008 Line 8 & 9 id int(11) NOT NULL auto_increment, signup date NOT NULL default '0000-00-00 00:00:00', Link to comment https://forums.phpfreaks.com/topic/86312-solved-mysql-insert-why-this-dont-work/#findComment-440971 Share on other sites More sharing options...
timmah1 Posted January 16, 2008 Author Share Posted January 16, 2008 I had a mistake, I was trying to make the field `signup` with date, but inserting 0000-00-00 00:00:00, instead of 0000-00-00, but I still get the same error Link to comment https://forums.phpfreaks.com/topic/86312-solved-mysql-insert-why-this-dont-work/#findComment-440979 Share on other sites More sharing options...
tapos Posted January 16, 2008 Share Posted January 16, 2008 Try this sql: mysql_query('CREATE TABLE IF NOT EXISTS `users` ( id int(11) NOT NULL auto_increment, date date NOT NULL default \'0000-00-00 00:00:00\', title varchar(255) NOT NULL default, name varchar(255) NOT NULL default, surname varchar(15) NOT NULL default , sex varchar(15) NOT NULL default, post varchar(15) NOT NULL default, mobile varchar(25) NOT NULL default, age varchar(25) NOT NULL default, transport varchar(255) NOT NULL default, file varchar(255) NOT NULL default, PRIMARY KEY(id))') or die(mysql_error()); Hope this will solve your problem -- Thanks, Tapos Pal http://tapos.wordpress.com Link to comment https://forums.phpfreaks.com/topic/86312-solved-mysql-insert-why-this-dont-work/#findComment-440991 Share on other sites More sharing options...
timmah1 Posted January 16, 2008 Author Share Posted January 16, 2008 Thanks tapos, it didn't work, but I did this mysql_query('CREATE TABLE IF NOT EXISTS `users` ( id int(11) NOT NULL auto_increment, date date NOT NULL default \'0000-00-00 00:00:00\', title varchar(255) NOT NULL default \'\', name varchar(255) NOT NULL default \'\', surname varchar(15) NOT NULL default \'\', sex varchar(15) NOT NULL default \'\', post varchar(15) NOT NULL default \'\', mobile varchar(25) NOT NULL default \'\', age varchar(25) NOT NULL default \'\', transport varchar(255) NOT NULL default \'\', file varchar(255) NOT NULL default \'\', PRIMARY KEY(id))') or die(mysql_error()); And it worked perfectly! Thanks Link to comment https://forums.phpfreaks.com/topic/86312-solved-mysql-insert-why-this-dont-work/#findComment-441000 Share on other sites More sharing options...
revraz Posted January 16, 2008 Share Posted January 16, 2008 If you have access to phpmyadmin, you can create the table there and then it will generate SQL code for PHP that you can use. Link to comment https://forums.phpfreaks.com/topic/86312-solved-mysql-insert-why-this-dont-work/#findComment-441004 Share on other sites More sharing options...
timmah1 Posted January 16, 2008 Author Share Posted January 16, 2008 That's where I obtained the code in the first place. I was trying to make it easy for this person. I built the database for them, but I couldn't get access to phpmyadmin on their servier, so I build a install file, access it, ad viola! done. Thanks for everyone's help Link to comment https://forums.phpfreaks.com/topic/86312-solved-mysql-insert-why-this-dont-work/#findComment-441015 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.