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 '[email protected]' 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); } ?> Link to comment https://forums.phpfreaks.com/topic/66462-plz-check-the-code/ 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`. Link to comment https://forums.phpfreaks.com/topic/66462-plz-check-the-code/#findComment-332772 Share on other sites More sharing options...
beboo002 Posted August 24, 2007 Author Share Posted August 24, 2007 thanks for reply still not working Link to comment https://forums.phpfreaks.com/topic/66462-plz-check-the-code/#findComment-332776 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) Link to comment https://forums.phpfreaks.com/topic/66462-plz-check-the-code/#findComment-332784 Share on other sites More sharing options...
beboo002 Posted August 24, 2007 Author Share Posted August 24, 2007 Any one :'( Link to comment https://forums.phpfreaks.com/topic/66462-plz-check-the-code/#findComment-332939 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.