DamienRoche Posted February 28, 2009 Share Posted February 28, 2009 I have no idea what's happening here. So I have a table. Two of the fields are id and qid. The id is auto_incremented sot hat's not an issue....but when I insert the first data and specifically tell it to set qid as 1, it always sets it as 0. I put the value in the actual sql instead of passing through variable to be sure, but it's still behaving the same.. Here's the function: <?php function addnewq($qtext, $ans1, $ans2, $fol1, $fol2){ global $badfeed; mysql_query("insert into questions (qid,question,ans1,ans2,fol1,fol2) values ('1','$qtext','$ans1','$ans2','$fol1','$fol2')") or die($badfeed[] = "unable to insert data into table"); } ?> Any ideas? Do I need to specify something else to lift this restriction? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/147338-new-entry-in-table-is-not-inserting-1-in-columnnot-auto_incremented/ Share on other sites More sharing options...
Stephen68 Posted February 28, 2009 Share Posted February 28, 2009 What is the table field set to? Quote Link to comment https://forums.phpfreaks.com/topic/147338-new-entry-in-table-is-not-inserting-1-in-columnnot-auto_incremented/#findComment-773391 Share on other sites More sharing options...
aliento Posted February 28, 2009 Share Posted February 28, 2009 if you put the value in the actual sql instead of passing through variable to be sure, but it's still behaving the same.. then there is something with the qid field db settings as it is obvious . So its better to export the table structure and post it here Quote Link to comment https://forums.phpfreaks.com/topic/147338-new-entry-in-table-is-not-inserting-1-in-columnnot-auto_incremented/#findComment-773394 Share on other sites More sharing options...
DamienRoche Posted February 28, 2009 Author Share Posted February 28, 2009 I figured that. I've messed around with the table/database/column settings but can't come up with anything. Here's the table structure: SET SQL_MODE="NO_AUTO_VALUE_ON_ZERO"; -- -- Database: `db1` -- -- -------------------------------------------------------- -- -- Table structure for table `questions` -- CREATE TABLE `questions` ( `id` int(255) NOT NULL auto_increment, `qid` int(100) NOT NULL, `question` varchar(500) NOT NULL, `ans1` varchar(30) NOT NULL, `ans2` varchar(30) NOT NULL, `fol1` int(100) NOT NULL, `fol2` int(100) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=11 ; Thanks for your help. Quote Link to comment https://forums.phpfreaks.com/topic/147338-new-entry-in-table-is-not-inserting-1-in-columnnot-auto_incremented/#findComment-773399 Share on other sites More sharing options...
daveoffy Posted February 28, 2009 Share Posted February 28, 2009 change qid from int to VARCHAR. That should work. Quote Link to comment https://forums.phpfreaks.com/topic/147338-new-entry-in-table-is-not-inserting-1-in-columnnot-auto_incremented/#findComment-773404 Share on other sites More sharing options...
DamienRoche Posted February 28, 2009 Author Share Posted February 28, 2009 Hi Dave, that's what I thought, but I can't even insert a number on it's own with a field set to varchar. Thanks any way...hopefully I'll crack it soon. Quote Link to comment https://forums.phpfreaks.com/topic/147338-new-entry-in-table-is-not-inserting-1-in-columnnot-auto_incremented/#findComment-773405 Share on other sites More sharing options...
daveoffy Posted February 28, 2009 Share Posted February 28, 2009 Oh, I know what should work. Change not null to '1' than for your code replace with this mysql_query("insert into questions (question,ans1,ans2,fol1,fol2) values ('$qtext','$ans1','$ans2','$fol1','$fol2')") or die($badfeed[] = "unable to insert data into table"); It will just auto set qid to 1 Quote Link to comment https://forums.phpfreaks.com/topic/147338-new-entry-in-table-is-not-inserting-1-in-columnnot-auto_incremented/#findComment-773406 Share on other sites More sharing options...
DamienRoche Posted February 28, 2009 Author Share Posted February 28, 2009 I've already tried that as well. It does the same thing. It defaults to 0, NULL is treated as blank. I thought maybe that was part of the issue...strange. I can set it to anything past 1, just not 1 itself. Thanks again. Quote Link to comment https://forums.phpfreaks.com/topic/147338-new-entry-in-table-is-not-inserting-1-in-columnnot-auto_incremented/#findComment-773409 Share on other sites More sharing options...
daveoffy Posted February 28, 2009 Share Posted February 28, 2009 I've already tried that as well. It does the same thing. It defaults to 0, NULL is treated as blank. I thought maybe that was part of the issue...strange. I can set it to anything past 1, just not 1 itself. Thanks again. So you can't set the default to 1? It changes it back to 0? Quote Link to comment https://forums.phpfreaks.com/topic/147338-new-entry-in-table-is-not-inserting-1-in-columnnot-auto_incremented/#findComment-773410 Share on other sites More sharing options...
DamienRoche Posted February 28, 2009 Author Share Posted February 28, 2009 That's right. It's all very strange. I've set the null option to 'not null' and set the default for that field to 1. Then I simply inserted data without inserting anything into that field and it's defaulted to 0. This is crazy. I've actually changed it myself from within phpmyadmin and used the mysql query it used to change the value...nothing. I even used an update query (similar to above) to change that value to 1 from a 2, which is what I can enter with the query...still, nothing. Thanks any way. Looks like I'm gonna have to approach this differently. Quote Link to comment https://forums.phpfreaks.com/topic/147338-new-entry-in-table-is-not-inserting-1-in-columnnot-auto_incremented/#findComment-773414 Share on other sites More sharing options...
DamienRoche Posted February 28, 2009 Author Share Posted February 28, 2009 Ok, so all I know is that I can't set this value to 1 using a mysql insert or update query, unless there is more than 1 record. Any ideas, anyone? Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/147338-new-entry-in-table-is-not-inserting-1-in-columnnot-auto_incremented/#findComment-773427 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.