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 '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);

 

}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.