Jump to content

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


DamienRoche

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.

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.