I am making a from in php and inserting values in members table.Structure of members table is:
id varchar(30) not null primary key
username varchar(15)
password varchar(15)
when i insert values in table using $_POST[] it gives error
Error:Duplicate entry 'john' for key 'PRIMARY' whereas there is no entry in my table as john.Code is:
It gives the error but at the same time also inserts values in the table.why it is giving error even when inserting values in the table?
id varchar(30) not null primary key
username varchar(15)
password varchar(15)
when i insert values in table using $_POST[] it gives error
Error:Duplicate entry 'john' for key 'PRIMARY' whereas there is no entry in my table as john.Code is:
Code:
<?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("seed_bank", $con); $sql = "insert into members(id,username,password) values('$_POST[emailid]','$_POST[firstname]','$_POST[password]')"; print $sql; $result=mysql_query($sql); $count=mysql_num_rows($result); if($count==1) { echo "Registration SUCCCESSFUL"; } if(!mysql_query($sql,$con)) { die('Error:'.mysql_error()); } else {echo"Registration succcessful";} mysql_close($con); ?>
Comment