Jump to content

More Database Troubles - Not adding and more


DannyM

Recommended Posts

Hello everyone!

 

I've run into a glitch in my Add Employee database. It doesn't want to add an Employee if there are no employees already in the database, and when there are, it adds the employee as many times as there are employees(IE, I have 2 employees in the database it adds the new employee twice, three employees it adds the employee three times, et cetera)

 

<?php
//Created by Danny Martin
if($_COOKIE["User"] != "0001" || !$_COOKIE["User"])
{
header("Location: Login.php");
}

if(isset($_POST["back"]))
{
header("Location: userCP.php");
}

//connect to the database
$con=mysql_connect("***********","******","************");
//Select the database
mysql_select_db("easyswipe_timecardtest",$con);


//Check to see what they clicked
if(isset($_POST["submit"]))
{

$sql="SELECT * FROM employees";
$result=mysql_query($sql,$con);
while($row = mysql_fetch_array($result))
{
if($row['ID'] == $_POST["ID"])
{
echo "<b>ID already taken!</b>";
}
else
{

//Insert into everything
$sql=mysql_query("INSERT INTO employees(Name, ID,Address,Phone)
VALUES('$_POST[Name]', '$_POST[iD]', '$_POST[Address]' , 

'$_POST[phone]')");


$sql=mysql_query("INSERT INTO Jan(Name, ID)
VALUES('$_POST[Name]', '$_POST[iD]')");

$sql=mysql_query("INSERT INTO Feb(Name, ID)
VALUES('$_POST[Name]', '$_POST[iD]')");

$sql=mysql_query("INSERT INTO Mar(Name, ID)
VALUES('$_POST[Name]', '$_POST[iD]')");

$sql=mysql_query("INSERT INTO Apr(Name, ID)
VALUES('$_POST[Name]', '$_POST[iD]')");

$sql=mysql_query("INSERT INTO May(Name, ID)
VALUES('$_POST[Name]', '$_POST[iD]')");

$sql=mysql_query("INSERT INTO Jun(Name, ID)
VALUES('$_POST[Name]', '$_POST[iD]')");

$sql=mysql_query("INSERT INTO Jul(Name, ID)
VALUES('$_POST[Name]', '$_POST[iD]')");

$sql=mysql_query("INSERT INTO Aug(Name, ID)
VALUES('$_POST[Name]', '$_POST[iD]')");

$sql=mysql_query("INSERT INTO Sep(Name, ID)
VALUES('$_POST[Name]', '$_POST[iD]')");

$sql=mysql_query("INSERT INTO M1(Name, ID)
VALUES('$_POST[Name]', '$_POST[iD]')");

$sql=mysql_query("INSERT INTO Nov(Name, ID)
VALUES('$_POST[Name]', '$_POST[iD]')");

$sql=mysql_query("INSERT INTO M2(Name, ID)
VALUES('$_POST[Name]', '$_POST[iD]')");


}
}
}




//Center everything
echo'<center>
<img src="logo.png"/>';

echo "<form action='addEmployee.php' method='POST'>";
echo '<b>Employee Name</b> - <input type="text" name="Name"/>';
echo '<br/>';
echo '<b>Employee Phone</b> - <input type = "text" name = "phone"/>';
echo '<br/>';
echo '<b>Employee Address</b> - <input type = "text" name = "Address"/>';
echo '<br/>';
echo '<b>Employee ID</B> - <input type="text" name="ID"/>';
echo '<br/>';
echo '<input type="submit" name="submit" value="Add Employee"/>';
echo '<input type="submit" name="back" value="Return"/>';
echo '</form>';


?>

 

 

What am I doing wrong?

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.