...

View Full Version : Data does not go into database



Bowers007
01-26-2010, 03:15 PM
Hello I have a employee training database and need to be able to add and update employees to it. I had it working and made a few changes and now it doesn't insert data into the database and i can't figure out what happened. (all I did was add some more fields) I get no error just a blank white page. First I need to get it to add a new employee working again.
Here is what I have.

TrainingDataBaseAdd.php File:


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>ADD a NEW EMPLOYEE Training Record</title>

<meta name="keywords" content="HTML, CSS, PHP" /> </meta>

<link rel="stylesheet" type="text/css" href="TrainingDataBase.css">

</head>

<body>

<br>
<br>

<!-- ADD NEW EMPLOYEE and TRAINING -->

<h1 align="center"><u><strong><font face="arial">Add New Employee Training Record</font></strong></u></h1>

<br>

<h3 align="center"><strong><font face="arial">PLEASE FILL IN <u>EVERY</u> BOX</font></strong></h3>

<br>
<h2 align="center"><u><strong><font face="arial">Add New Employee Information</font></strong></u></h2>
<br>

<form action="AddTraining.php" method="post">
Please enter a EMPLOYEE NUMBER:
<input type="text" name="Emp_Id" />

<br>
<br>

<form action="AddTraining.php" method="post">
Please enter a FIRST NAME: <input type="text" name="FirstName" />

<br>
<br>

<form action="AddTraining.php" method="post">
Please enter a LAST NAME: <input type="text" name="LastName" />

<br>
<br>

<form action="AddTraining.php" method="post">
Please enter a DEPARTMENT: <input type="text" name="Dept" />

<br>
<br>

<form action="AddTraining.php" method="post">
Please enter a SHIFT: <input type="text" name="Shift" />

<br>
<br>
<br>
<h2 align="center"><u><strong><font face="arial">Add New Quality Training</font></strong></u></h2>
<br>

<form action="AddTraining.php" method="post">
Please enter the date of ISO 13485 Internal Audit Training: <input type="text" name="iso13485" /> example: mm/dd/yyyy OR 0 for NO Training

<br>
<br>

<form action="AddTraining.php" method="post">
Please enter the date of ISO 9001 Training: <input type="text" name="iso9001" /> example: mm/dd/yyyy OR 0 for NO Training

<br>
<br>

<form action="AddTraining.php" method="post">
Please enter the date of QUALITY Training: <input type="text" name="quality" /> example: mm/dd/yyyy OR 0 for NO Training

<br>
<br>

<form action="AddTraining.php" method="post">
Please enter the date of DHR Training: <input type="text" name="dhr" /> example: mm/dd/yyyy OR 0 for NO Training

<br>
<br>

<form action="AddTraining.php" method="post">
Please enter the date of ORIENTATION: <input type="text" name="orientation" /> example: mm/dd/yyyy OR 0 for NO Training

<br>
<br>

<form action="AddTraining.php" method="post">
Please enter the date of WORK INSTRUCTIONS Training: <input type="text" name="workinstructions" /> example: mm/dd/yyyy OR 0 for NO Training

<br>
<br>

<form action="AddTraining.php" method="post">
Please enter the date of 6S Training: <input type="text" name="6S" /> example: mm/dd/yyyy OR 0 for NO Training

<br>
<br>
<br>
<br>

<center><input type="submit" value="Add New Employee"></center>
</form>

<br>
<br>

</body>

</html>


Here is the AddTraining.php File:



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>Employee Has Been Added to Database</title>

<meta name="keywords" content="HTML, CSS, PHP" /> </meta>

<link rel="stylesheet" type="text/css" href="TrainingDataBase.css">

</head>

<body>

<div align="center">

<br>

<?php

$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("training_db", $con);

// Employee Data Variables
$Emp_Id = $_POST['Emp_Id'];
$FirstName = $_POST['FirstName'];
$LastName = $_POST['LastName'];
$Dept = $_POST['Dept'];
$Shift = $_POST['Shift'];

// Quality Data Variables
$iso13485 = $_POST['iso13485'];
$iso9001 = $_POST['iso9001'];
$quality = $_POST['quality'];
$dhr = $_POST['dhr'];
$orientation = $_POST['orientation'];
$workinstructions = $_POST['workinstructions'];
$6S = $_POST['6S'];

// Insert Data Into Database Tables

mysql_query(INSERT INTO employee('Emp_Id',
'FirstName',
'LastName',
'Dept',
'Shift'
)
VALUES ('$Emp_Id',
'$FirstName',
'$LastName',
'$Dept',
'$Shift'
));

mysql_query(INSERT INTO quality('Emp_Id',
'iso1348',
'iso9001',
'quality',
'dhr',
'orientation',
'workinstructions',
'6S'
)
VALUES ('$Emp_Id',
'$iso13485',
'$iso9001',
'$quality',
'$dhr',
'$orientation',
'$workinstructions',
'$6S'
));

mysql_close($con);

?>

<h3 align="center"><u><strong><font face="arial"><?php echo $FirstName." ".$LastName;
?> Has Been Added to Database</font></strong></u></h3>

<br>
<br>

</div>

</body>

</html>

Thanks for any and all help.

abduraooft
01-26-2010, 03:23 PM
If you are not getting any error message, turn ON error reporting on your server (http://www.codingforums.com/showpost.php?p=617060&postcount=13).

masterofollies
01-26-2010, 04:28 PM
Blank pages usually mean the function cannot load. I suspect it may be because you don't have a isset $_POST in your AddTraining.php

Try this to see if anything changes. If it doesn't we will move to the next possible attempt.

AddTraining.php



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<title>Employee Has Been Added to Database</title>

<meta name="keywords" content="HTML, CSS, PHP" /> </meta>

<link rel="stylesheet" type="text/css" href="TrainingDataBase.css">

</head>

<body>

<div align="center">

<br>

<?php

$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("training_db", $con);
if (isset($_POST['submit'])) {
// Employee Data Variables
$Emp_Id = $_POST['Emp_Id'];
$FirstName = $_POST['FirstName'];
$LastName = $_POST['LastName'];
$Dept = $_POST['Dept'];
$Shift = $_POST['Shift'];

// Quality Data Variables
$iso13485 = $_POST['iso13485'];
$iso9001 = $_POST['iso9001'];
$quality = $_POST['quality'];
$dhr = $_POST['dhr'];
$orientation = $_POST['orientation'];
$workinstructions = $_POST['workinstructions'];
$6S = $_POST['6S'];

// Insert Data Into Database Tables

mysql_query(INSERT INTO employee('Emp_Id',
'FirstName',
'LastName',
'Dept',
'Shift'
)
VALUES ('$Emp_Id',
'$FirstName',
'$LastName',
'$Dept',
'$Shift'
));

mysql_query(INSERT INTO quality('Emp_Id',
'iso1348',
'iso9001',
'quality',
'dhr',
'orientation',
'workinstructions',
'6S'
)
VALUES ('$Emp_Id',
'$iso13485',
'$iso9001',
'$quality',
'$dhr',
'$orientation',
'$workinstructions',
'$6S'
));

mysql_close($con);

?>

<h3 align="center"><u><strong><font face="arial"><?php echo $FirstName." ".$LastName;
}
?> Has Been Added to Database</font></strong></u></h3>

<br>
<br>

</div>

</body>

</html>

Fou-Lu
01-26-2010, 05:04 PM
Variables cannot start with a number:


// Quality Data Variables
$iso13485 = $_POST['iso13485'];
$iso9001 = $_POST['iso9001'];
$quality = $_POST['quality'];
$dhr = $_POST['dhr'];
$orientation = $_POST['orientation'];
$workinstructions = $_POST['workinstructions'];
$6S = $_POST['6S'];


Once that problem has been corrected, it will likely work as expected.

Bowers007
01-26-2010, 05:24 PM
Fou-Lu you ROCK. :thumbsup: I didn't even think about the variable starting with a number. Changed it work perfect. Thanks so much that was about to drive me crazy... Now on to the next challenge updating the tables.

barkermn01
01-26-2010, 05:30 PM
mysql_query(INSERT INTO employee('Emp_Id',
'FirstName',

Erm, mysql_query requiers a string not a word,

E.G mysql_query("INSERT INTO `employee` (`Emp_Id`, `FirstName`)");

Please notice the correct syntax you only use '' qotes for input ` for names ` is the key to the left of the one and a english/us/GB keyboard and ' is the second key in from the return Please learn syntax

Bowers007
01-26-2010, 07:09 PM
OK I need to be able to update the records in the database. How I have it set up is you select the employee it update. Then goto the next page and it lists the employee records from the database. Change the record you need to and click submit and it SHOULD update the record. Everything works and looks as it should but when I check the database it doesn't update. Here are my php files

Here is the postupdate.php file


<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>Updated EmployeeTraining Records</title>

<meta name="keywords" content="HTML, CSS, PHP" /> </meta>

</head>

<body>

<br>
<br>

<?php
foreach($HTTP_POST_VARS as $varname => $value)
$formVars[$varname]=$value;

require_once("config.php");

$db1=mysql_connect($dbhost, $dbuname, $dbpass);
mysql_select_db("training_db");

echo "Record updated&nbsp;<a href=\"TrainingUpdate.html\"> click here</a> to update another record<br>";

$query="UPDATE `employee` SET ".

"FirstName= \"".$formVars["FirstName"]."\",".
"LastName= \"".$formVars["LastName"]."\",".
"Dept= \"".$formVars["Dept"]."\"".
"Shift= \"".$formVars["Shift"]."\"".

"\" WHERE Emp_Id = \"".$formVars["EID"]."\"";

mysql_query($query);
mysql_close($db1);
?>

</body>

</html>


Here is the TrainingUpdate.php file:


<?php
foreach($HTTP_POST_VARS as $varname => $value)
$formVars[$varname]=$value;

require_once("config.php");

$db1=mysql_connect($dbhost, $dbuname, $dbpass);
mysql_select_db("training_db");

$query="SELECT * FROM employee WHERE Emp_Id = \"".$formVars["EID"]."\"";

$result=mysql_query($query);
$row=mysql_fetch_array($result);
$formVars = array();

$formVars["FirstName"]=$row["FirstName"];
$formVars["LastName"]=$row["LastName"];
$formVars["Dept"]=$row["Dept"];
$formVars["Shift"]=$row["Shift"];

mysql_close($db1);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<title>Existing Employee Training Records</title>

<meta name="keywords" content="HTML, CSS, PHP" /> </meta>

</head>

<body>

<br>
<br>

<div align="center">
<form method="post" action="postupdate.php">

<table>

<col span="1" align="right">

<tr>
<td><font color="blue">First Name:</font></td>
<td><input type="text" name="FirstName"
value="<? echo $formVars["FirstName"]; ?>" size=50></td>
</tr>
<tr>
<td><font color="blue">Last Name:</font></td>
<td><input type="text" name="LastName"
value="<? echo $formVars["LastName"]; ?>" size=50></td>
</tr>
<tr>
<td><font color="blue">Department:</font></td>
<td><input type="text" name="Dept"
value="<? echo $formVars["Dept"]; ?>" size=50></td>
</tr>
<tr>
<td><font color="blue">Shift:</font></td>
<td><input type="text" name="Dept"
value="<? echo $formVars["Shift"]; ?>" size=50></td>
</tr>

</table>

<br>

<input type="submit" value="Submit">
</form>
</div>

</table>

<br>

<input type="submit" value="Submit">

<br>
<br>

</form>

<br>
<br>

</div>

</body>

</html>


Thanks for all the help

masterofollies
01-26-2010, 08:04 PM
Good catch fou lu, I also forgot variables can't start with numbers.

Um I believe your query is suppose to be like this.


$query = ("UPDATE `employee` SET FirstName=".$formVars["FirstName"].",
LastName=".$formVars["LastName"].",Dept=".$formVars["Dept"]."Shift=".$formVars["Shift"]." WHERE Emp_Id = '".$formVars["EID"]."'");



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum