beboo002 Posted August 24, 2007 Share Posted August 24, 2007 i hav written a code where new employee insert and update both in one script my problem is when i insert new employee it working but when i update the employee record it is not working it showing error ''Error: Duplicate entry 'beboo002@gmail.com' for key 1 All the value pass through the form and pass suceessfully. the code paste here <?php if($_POST['Submit']!="") { $link=mysql_connect("localhost","root",""); if(!$link) die("can not connect to mysql"); mysql_select_db("timesheet",$link); $username1=$HTTP_POST_VARS['text1']; $sql="select username from login where username ='".$_POST['text1']."' "; $result=mysql_query($sql,$link); $row = mysql_fetch_array( $result ); $username = $row['username']; echo $username; echo $username1; echo "'".$_POST['text3']."'"; if($username == $username1) { $update1 = "UPDATE login SET username= '".$_POST['text1']."' , password= '".$_POST['text2']."', name= '".$_POST['text3']."' WHERE username ='".$_POST['text1']."' "; echo "'".$_POST['text1']."'"; if (!mysql_query($update1, $link)) { die('Error: ' . mysql_error()); } } if($username!=$username1) { $sql1 ="insert into login(username,password,name) VALUES ('".$_POST['text1']."','".$_POST['text1']."','".$_POST['text1']."')"; if (!mysql_query($sql1,$link)) { die('Error: ' . mysql_error()); echo "1 record added"; } } mysql_close($link); } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted August 24, 2007 Share Posted August 24, 2007 Niether should be working, password is a reserved word and needs to be surrounded by `backticks`. Quote Link to comment Share on other sites More sharing options...
beboo002 Posted August 24, 2007 Author Share Posted August 24, 2007 thanks for reply still not working Quote Link to comment Share on other sites More sharing options...
beboo002 Posted August 24, 2007 Author Share Posted August 24, 2007 its not taken if condition for update if($username == $username1) Quote Link to comment Share on other sites More sharing options...
beboo002 Posted August 24, 2007 Author Share Posted August 24, 2007 Any one :'( Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.