Jump to content

plz check the code


beboo002

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.