winmastergames Posted February 25, 2008 Share Posted February 25, 2008 I cant seem to get this to work can someone plese enlighten me on whats wrong. im trying to insert data into the table (SQL of table below) CREATE TABLE `tue23` ( `id` int(11) NOT NULL auto_increment, `title` varchar(200) collate latin1_general_ci default NULL, `slogan` varchar(200) collate latin1_general_ci default NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 COLLATE=latin1_general_ci AUTO_INCREMENT=1 ; Im trying to use this script but it doesnt work <?php // Connects to your Database mysql_connect("localhost", "root", "com12345") or die(mysql_error()); mysql_select_db("swd-dbweb") or die(mysql_error()); mysql_query("INSERT INTO tue23 VALUES ( '1', titlename, 'sloganname' )"); Print "Your table has been populated"; ?> thanks very much Link to comment https://forums.phpfreaks.com/topic/92975-storing-mysql-data-into-tables/ Share on other sites More sharing options...
DarkerAngel Posted February 25, 2008 Share Posted February 25, 2008 <?php // Connects to your Database mysql_connect("localhost", "root", "com12345") or die(mysql_error()); mysql_select_db("swd-dbweb") or die(mysql_error()); mysql_query("INSERT INTO tue23 VALUES ( '', 'titlename', 'sloganname')") or die(mysql_error()); Print "Your table has been populated"; ?> Link to comment https://forums.phpfreaks.com/topic/92975-storing-mysql-data-into-tables/#findComment-476364 Share on other sites More sharing options...
revraz Posted February 26, 2008 Share Posted February 26, 2008 You are trying to insert 1 into an auto_increment field, you can't do that. Link to comment https://forums.phpfreaks.com/topic/92975-storing-mysql-data-into-tables/#findComment-476458 Share on other sites More sharing options...
DyslexicDog Posted February 26, 2008 Share Posted February 26, 2008 You are trying to insert 1 into an auto_increment field, you can't do that. I thought auto_increment only supplied a number if one wasn't given to it? Link to comment https://forums.phpfreaks.com/topic/92975-storing-mysql-data-into-tables/#findComment-476464 Share on other sites More sharing options...
unsider Posted February 26, 2008 Share Posted February 26, 2008 It does, he was trying to supply it with 1, and like rev said, you can't do that. Leave it alone for this specific purpose I guess is the point, but like many things, I could be wrong. Link to comment https://forums.phpfreaks.com/topic/92975-storing-mysql-data-into-tables/#findComment-476471 Share on other sites More sharing options...
jedney Posted February 26, 2008 Share Posted February 26, 2008 Instead of entering a number for 'id', enter 'NULL'. Link to comment https://forums.phpfreaks.com/topic/92975-storing-mysql-data-into-tables/#findComment-476482 Share on other sites More sharing options...
Barand Posted February 26, 2008 Share Posted February 26, 2008 You are trying to insert 1 into an auto_increment field, you can't do that. You can. Use NULL if you wanr it to auto_inc (or omit it completely) but it will accept a value so long as that value doen't already exist. Link to comment https://forums.phpfreaks.com/topic/92975-storing-mysql-data-into-tables/#findComment-476499 Share on other sites More sharing options...
EchoFool Posted February 26, 2008 Share Posted February 26, 2008 You are trying to insert 1 into an auto_increment field, you can't do that. You can. Use NULL if you wanr it to auto_inc (or omit it completely) but it will accept a value so long as that value doen't already exist. Yeh but with my guess is the auto-increment is also primary key... so im going to guess that to insert a value would be pretty difficult to find a unique without a pre-check everytime. But again as said in the other post we dont know what the field is! >.< Link to comment https://forums.phpfreaks.com/topic/92975-storing-mysql-data-into-tables/#findComment-476504 Share on other sites More sharing options...
Xeoncross Posted February 26, 2008 Share Posted February 26, 2008 <?php // Connects to your Database mysql_connect("localhost", "root", "com12345") or die(mysql_error()); mysql_select_db("swd-dbweb") or die(mysql_error()); mysql_query("INSERT INTO tue23 VALUES ( '1', titlename, 'sloganname' )"); Print "Your table has been populated"; ?> Into this: <?php // Connects to your Database mysql_connect('localhost', 'root', 'com12345') or die(mysql_error()); mysql_select_db('swd-dbweb') or die(mysql_error()); if( mysql_query('INSERT `titlename`, `sloganname` INTO `table` VALUES (\''. $titlename. '\', \''. $sloganname. '\' )') ) { print "Your table has been populated"; } else { print mysql_error(); } ?> Don't ever specify the ID field when it is set to "auto_increment" - MySQL handles that for you. Just ignore it Link to comment https://forums.phpfreaks.com/topic/92975-storing-mysql-data-into-tables/#findComment-476547 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.