hi... im trying to insert a row into the database...

but the query is not run successfully..

$sql = "INSERT INTO temp_db (fname,mname,lname,dob,gender,email,country,phno,mobile,userid,password,mti,rtime)
	VALUES ('$fname','$mname','$lname','$dob','$gen','$mail','$country','$phno','$mob','$uid','$pass','$mt','$rtime')";

$res = mysql_query($sql) or die("cud not add record");
echo mysql_error();

this is the code..... im gettin the error from the Die part of the query..

need help....

CREATE TABLE IF NOT EXISTS `temp_db` (
  `fname` varchar(30) NOT NULL,
  `mname` varchar(30) NOT NULL,
  `lname` varchar(30) NOT NULL,
  `dob` date NOT NULL,
  `gender` varchar(10) NOT NULL,
  `email` varchar(40) NOT NULL,
  `country` varchar(30) NOT NULL,
  `phno` int(20) NOT NULL,
  `mobile` int(20) NOT NULL,
  `userid` varchar(30) NOT NULL,
  `password` varchar(30) NOT NULL,
  `mti` varchar(40) NOT NULL,
  `rtime` date NOT NULL,
  PRIMARY KEY (`userid`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

this is the table im using...

help Plz...

Dani AI

Generated

Good catch by — a missing value in the VALUES list is a very common cause of an INSERT failing when you supply an explicit column list. was also right to suggest checking the database error first; the native error text usually tells you whether it is a column/value count mismatch, a duplicate key, a bad date format, etc.

Quick troubleshooting checklist:

  • Log or echo the final SQL string before execution and verify the number of columns equals the number of values.
  • Check for stray commas or unbalanced quotes that can change the value count.
  • Confirm NOT NULL columns are getting values (or have defaults).
  • Make sure date fields are supplied in a valid format (YYYY-MM-DD) or use a TIMESTAMP/DATETIME default.
  • If the failure is a duplicate key, check the primary key value rather than column counts.

Schema and safety suggestions (practical, years-later advice):

Modernize the database access:

Actionable next steps: reproduce the failing SQL string, count columns vs values, fix schema/data types as needed, and migrate to prepared statements for safer, more reliable inserts.

Recommended Answers

All 2 Replies

Replace

$res = mysql_query($sql) or die("cud not add record");

with

$res = mysql_query($sql) or die(mysql_error());

and paste the error message too.

dude.. i found out the prob,i was facing...

i missed a field while inserting...

pritaeas thanks for replying...
sure need ur help, iin upcoming days.. coz hav lots of prob im facing here

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.