Jump to content

new entry in table is not inserting '1' in column(not auto_incremented)...?


Recommended Posts

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.

 

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

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.

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.

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

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.

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?

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.

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.