0

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.

Edited by ans2007kumar: n/a

2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by akshatgoel
0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.