I have created a register page which send the data of user from that page to my query processing page.
Problem is some of my database table field takes integer value but through post i get only string values i try to change them through type cast but not good it changes to long not int.
Second on processing the query i get this error
Error: Column count doesn't match value count at row 1

<?php
  $con=mysql_connect("localhost","root","123"); 
  mysql_select_db("shop",$con);    
  $id=rand();
  $i=intval($id);
  $m=intval($_POST[mob]);
  $p=intval($_POST[pin]);
  $c=intval($_POST[credit]);
  $sql="insert into shop Values($_POST[name],$_POST[city],$_POST[state],$p,$_POST[coun],$m,$c,$i,$_POST[email],$_POST[un],$_POST[pass],$_POST[add])" ;
if (!mysql_query($sql,$con))
  {
  die('Error: ' . mysql_error());
  }
echo "1 record added";
mysql_close($con)
?>

"Name","varchar(60)","NO","",""
"City","varchar(50)","NO","",""
"State","varchar(50)","NO","",""
"Pin","int(10)","NO","",""
"Country","varchar(50)","NO","",""
"MobNo","int(12)","NO","",""
"CreditNo","int(30)","NO","",""
"Id","int(10)","NO","PRI",""
"EmailID","varchar(60)","NO","",""
"User","varchar(40)","NO","",""
"Pass","varchar(40)","NO","",""
"Address","varchar(80)","NO","",""

this is my db structure.

Hi,

intval function will definitely parse text to number.

The second error you are stating, is coming because you are not using ' (single inverted comma) around the text you are passing into the mysql_query.

It should have been like this

$sql="insert into shop Values('$_POST[name]','$_POST[city]','$_POST[state]',$p,'$_POST[coun]',$m,$c,$i,'$_POST[email]','$_POST[un]','$_POST[pass]','$_POST[add]')" ;

Thanks, Akshat

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.