...

View Full Version : Need help finishing this PHP MySQL Please Help



Bowers007
01-12-2010, 05:37 PM
Good Day, I am trying to create a Training database using PHP and MySQL. This needs to be able to search by employee name using the emp_id and return the dates of the training that are in the MySQL database as results. I also need to be able to add a new employee and update existing employees. I have a good start and I think (hope) I'm close. I have developed the search and the add a new employee PHP pages. I have also built the database. Can someone please look over this and help me finish this as I am getting kinda lost in what to do next and how to connect it all. I have tried to use it but get no results ifrom the search just the echo PHP coding as results. Here is what I have so far:

This is the TrainingDataBaseSearch.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>Search for a EmployeeTraining Record</title>

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

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

</head>

<body>

<div align="center">
<p>
<img src="Images/dsHeaderLogo.png"
width="950" height="125">

<br>

<!-- SEARCH TRAINING RECORDS -->

<h1 align="center"><u><strong><font face="arial">Search for a EmployeeTraining Record</font></strong></u></h1>
</p>

<br>
<br>

<form action="SearchResults.php" method="get">
<h4> Please Select a Employee: </h4>
<select name = "employee">
<option value=" ">Select Employee</option>
<option value="34">Joe Blow</option>
<option value="all">All Employees</option>
</select>

<br>
<br>

<input type="submit" value="SHOW TRAINING REPORT ">
</form>

</div>

<br>

<center>
<a href="TrainingDataBaseAdd.php"><img src="Images/AddTrainingBtn.png" alt="Add New Person to DataBase" /></a>
</center>

<br>
<br>

<center>
<a href="TrainingDataBaseUpdate.php"><img src="Images/UpdateTrainingBtn.png" alt="Click Here to UPDATE a Training Record" /></a>
</center>

</body>
</html>

This is the SearchResults.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>EmployeeTraining Record Results</title>

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

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

</head>

<body>

<div align="center">
<p>
<img src="Images/dsHeaderLogo.png"
width="950" height="125">

<br>

<!-- SEARCH PRODUCT DHR -->

<h1 align="center"><u><strong><font face="arial">EmployeeTraining Record Results</font></strong></u></h1>
</p>

<br>
<br>


<?php

mysql_connect("localhost", "root", "password");

mysql_select_db("training_db");

$query = mysql_query("SELECT * FROM employee WHERE employee = Emp_Id");
while ($row = mysql_fetch_array($query))
{
$Emp_Id = $row['Emp_Id'];
$LastName = $row['LastName'];
$FirstName = $row['FirstName'];
$Dept = $row['Dept'];
}

//Display Results in a Table

echo "<table align='center' table border='8'>
<tr>
<th>Employee Id</th>
<th>Last Name</th>
<th>Department</th><br>
<th>Diversity / Sexual Haarassment</th>
<th>BBP</th>
<th>LOTO</th>
<th>Haz Comm</th>
<th>PPE</th>
<th>Evacuation</th><br>
<th>ISO 13485</th>
<th>ISO 9001</th>
<th>Quality DHR</th>
<th>Orientation</th>
<th>Work Instructions</th><br>
<th>Handle Drilling</th>
<th>Assembly</th>
<th>Centerless Grinder</th>
<th>Fluter</th>
<th>Labels</th>
<th>Shafting</th>
<th>Molding</th
<th>Laser</th>
<th>Tipping</th>
<th>QC 5000</th>
<th>Calibration</th>
<th>Staking</th>
<th>End Stamp</th><br>
<th>Mazak</th>
<th>Fadal</th>
<th>Screw Machine</th>
<th>Fork Lift Safety</th>
</tr>";while($row = mysql_fetch_array($resulttraining))
{
echo "<tr>";
echo $Emp_Id = $row['Emp_Id'] . "</td>";
echo "<td align='center'>" . $row['FirstName'] . "</td>";
echo "<td align='center'>" . $row['LastName'] . "</td>";
echo "<td align='center'>" . $row['Dept'] . "</td>"<br>;
echo "<td align='center'>" . $row['diversity'] . "</td>";
echo "<td align='center'>" . $row['bbp'] . "</td>";
echo "<td align='center'>" . $row['loto'] . "</td>";
echo "<td align='center'>" . $row['hazcomm'] . "</td>";
echo "<td align='center'>" . $row['ppe'] . "</td>";
echo "<td align='center'>" . $row['evacutation'] . "</td>";
echo "<td align='center'>" . $row['iso13485'] . "</td>";
echo "<td align='center'>" . $row['iso9001'] . "</td>";
echo "<td align='center'>" . $row['qualitydhr'] . "</td>";
echo "<td align='center'>" . $row['orientation'] . "</td>";
echo "<td align='center'>" . $row['workinstructions'] . "</td>";
echo "<td align='center'>" . $row['handledrilling'] . "</td>";
echo "<td align='center'>" . $row['assembly'] . "</td>";
echo "<td align='center'>" . $row['cg'] . "</td>";
echo "<td align='center'>" . $row['fluter'] . "</td>";
echo "<td align='center'>" . $row['labels'] . "</td>";
echo "<td align='center'>" . $row['shafting'] . "</td>";
echo "<td align='center'>" . $row['molding'] . "</td>";
echo "<td align='center'>" . $row['laser'] . "</td>";
echo "<td align='center'>" . $row['tipping'] . "</td>";
echo "<td align='center'>" . $row['qc5000'] . "</td>";
echo "<td align='center'>" . $row['calibration'] . "</td>";
echo "<td align='center'>" . $row['staking'] . "</td>";
echo "<td align='center'>" . $row['stamp'] . "</td>";
echo "<td align='center'>" . $row['mazak'] . "</td>";
echo "<td align='center'>" . $row['fadal'] . "</td>";
echo "<td align='center'>" . $row['screw'] . "</td>";
echo "<td align='center'>" . $row['forklift'] . "</td>";

echo "</tr>";
}
echo "</table>";
mysql_close($DBConnect); }

echo "<div align=\"center\">".date("Y/m/d")."</div>";

?>

</div>

</body>
</html>

Here is the 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>

<div align="center">

<img src="Images/dsHeaderLogo.png" width="950" height="125">

</div>

<br>
<br>

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

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

<br>
<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>
<br>
<br>

<form action="AddTraining.php" method="post">
Please enter the date of DIVERSITY/ SEXUAL HARASSMENT Training: <input type="text" name="diversity" /> example: mm/dd/yyyy

<br>
<br>

<form action="AddTraining.php" method="post">
Please enter the date of BBP Training: <input type="text" name="bbp" /> example: mm/dd/yyyy

<br>
<br>

<form action="AddTraining.php" method="post">
Please enter the date of LOTO Training: <input type="text" name="loto" /> example: mm/dd/yyyy

<br>
<br>

<form action="AddTraining.php" method="post">
Please enter the date of HAZCOMM Training: <input type="text" name="hazcomm" /> example: mm/dd/yyyy

<br>
<br>

<form action="AddTraining.php" method="post">
Please enter the date of PPE Training: <input type="text" name="ppe" /> example: mm/dd/yyyy


<br>
<br>

<form action="AddTraining.php" method="post">
Please enter the date of EVACUATION Training: <input type="text" name="evacuation" /> example: mm/dd/yyyy


<br>
<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

<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

<br>
<br>

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

<br>
<br>

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

<br>
<br>

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

<br>
<br>

<form action="AddTraining.php" method="post">
Please enter the date of HANDLE DRILLING Training: <input type="text" name="handledrilling" /> example: mm/dd/yyyy

<br>
<br>

<form action="AddTraining.php" method="post">
Please enter the date of ASSEMBLY PACKAGE Training: <input type="text" name="assembly" /> example: mm/dd/yyyy

<br>
<br>

<form action="AddTraining.php" method="post">
Please enter the date of CENTERLESS GRINDING Training: <input type="text" name="cg" /> example: mm/dd/yyyy

<br>
<br>

<form action="AddTraining.php" method="post">
Please enter the date of FLUTER Training: <input type="text" name="fluter" /> example: mm/dd/yyyy

<br>
<br>

<form action="AddTraining.php" method="post">
Please enter the date of LABELS Training: <input type="text" name="labels" /> example: mm/dd/yyyy

<br>
<br>

<form action="AddTraining.php" method="post">
Please enter the date of SHAFTING Training: <input type="text" name="shafting" /> example: mm/dd/yyyy

<br>
<br>

<form action="AddTraining.php" method="post">
Please enter the date of MOLDING Training: <input type="text" name="molding" /> example: mm/dd/yyyy

<br>
<br>

<form action="AddTraining.php" method="post">
Please enter the date of LASER Training: <input type="text" name="laser" /> example: mm/dd/yyyy

<br>
<br>

<form action="AddTraining.php" method="post">
Please enter the date of TIPPING Training: <input type="text" name="tipping" /> example: mm/dd/yyyy

<br>
<br>

<form action="AddTraining.php" method="post">
Please enter the date of QC 5000 Training: <input type="text" name="qc5000" /> example: mm/dd/yyyy

<br>
<br>

<form action="AddTraining.php" method="post">
Please enter the date of CALIBRATION Training: <input type="text" name="calibration" /> example: mm/dd/yyyy

<br>
<br>

<form action="AddTraining.php" method="post">
Please enter the date of STAKING Training: <input type="text" name="staking" /> example: mm/dd/yyyy

<br>
<br>

<form action="AddTraining.php" method="post">
Please enter the date of END STAMP Training: <input type="text" name="stamp" /> example: mm/dd/yyyy

<br>
<br>

<form action="AddTraining.php" method="post">
Please enter the date of MAZAK Training: <input type="text" name="mazak" /> example: mm/dd/yyyy

<br>
<br>

<form action="AddTraining.php" method="post">
Please enter the date of FADAL Training: <input type="text" name="fadal" /> example: mm/dd/yyyy

<br>
<br>

<form action="AddTraining.php" method="post">
Please enter the date of SCREW MACHINE Training: <input type="text" name="screw" /> example: mm/dd/yyyy

<br>
<br>

<form action="AddTraining.php" method="post">
Please enter the date of FORK LIFT SAFETY Training: <input type="text" name="forklift" /> example: mm/dd/yyyy

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

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

<!-- END ADD NEW PRODUCT DHR -->

<?php

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

$Emp_Id = $_POST['Emp_Id'];
$LastName = $_POST['LastName'];
$FirstName = $_POST['FirstName'];
$Dept = $_POST['Dept'];

$diversity = $_POST['diversity'];
$bbp = $_POST['bbp'];
$loto = $_POST['loto'];
$hazcomm = $_POST['hazcomm'];
$ppe = $_POST['ppe'];
$evacuation = $_POST['evacuation'];

$iso13485 = $_POST['iso13485'];
$iso9001 = $_POST['iso9001'];
$qualitydhr = $_POST['qualitydhr'];
$orientation = $_POST['orientation'];
$workinstructions = $_POST['workinstructions'];

$handledrilling = $_POST['handledrilling'];
$assembly = $_POST['assembly'];
$cg = $_POST['cg'];
$fluter = $_POST['fluter'];
$labels = $_POST['labels'];
$shafting = $_POST['shafting'];
$molding = $_POST['molding'];
$laser = $_POST['laser'];
$tipping = $_POST['tipping'];
$qc5000 = $_POST['qc5000'];
$calibration = $_POST['calibration'];
$staking = $_POST['staking'];
$stamp = $_POST['stamp'];

$mazak = $_POST['mazak'];
$fadal = $_POST['fadal'];
$screw = $_POST['screw'];
$forklift = $_POST['forklift'];


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

mysql_query("INSERT INTO annual VALUES ('$Emp_Id','$diversity','$bbp','$loto','$hazcomm','$ppe','$evacuation')";

mysql_query("INSERT INTO quality VALUES ('$Emp_Id','$iso13485','$iso9001','$qualitydhr','$orientation','$workinstructions')";

mysql_query("INSERT INTO endo VALUES ('$Emp_Id','$handledrilling','$assembly','$cg','$fluter','$labels','$labels','$shafting','$molding', '$laser','$tipping','$qc5000','$calibration','$staking','$stamp')";

mysql_query("INSERT INTO ms VALUES ('$Emp_Id','$mazak','$fadal','$screw','$forklift')";

mysql_close($con);

?>

</body>
</html>

Here is the AddTraining.php File


<?php
$con = mysql_connect("localhost","root","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("training_db", $con);

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

mysql_query("INSERT INTO annual VALUES ('$Emp_Id','$diversity','$bbp','$loto','$hazcomm','$ppe','$evacuation')";

mysql_query("INSERT INTO quality VALUES ('$Emp_Id','$iso13485','$iso9001','$qualitydhr','$orientation','$workinstructions')";

mysql_query("INSERT INTO endo VALUES ('$Emp_Id','$handledrilling','$assembly','$cg','$fluter','$labels','$labels','$shafting','$molding', '$laser','$tipping','$qc5000','$calibration','$staking','$stamp')";

mysql_query("INSERT INTO ms VALUES ('$Emp_Id','$mazak','$fadal','$screw','$forklift')";

mysql_close($con);
?>

I would really appreciate any and all help with this to finish it. Thank You in advance for any help.

atheistrical
01-12-2010, 07:28 PM
Read the rules of the forum, coz your post sounds like "homework".

Nonetheless, I'll try to help you out with the basics.

For your SearchResults.php file.

When a form is submitted, the submitted data is to be caught by your action script for processing, which is missing in your file.

Say, a form submits a value by


<form action="search.php" method="post">
<input type="text" name="test" />
<input type="submit" />
</form>


The action script i.e. search.php in my case must know that some data was forwarded to it for processing, hence my search.php will contain


<?php
//**search.php
if(isset($_POST["test"]))
{
//***Process the variable $_POST["test"]
$post_data=$_POST["test"]; //**Storing the post value in a variable

//***Now say, displaying the value******

echo $post_data;

//***Or, fetching data from the database
$q="SELECT abc FROM table WHERE column='{$post_data}'";
$result=mysql_query($q);

//***Now display the retrieved values. Let's say 2 values in one row were returned. Then,

while($row=mysql_fetch_row($result))
{
echo "<br />".$row[0];
echo "<br />".$row[1];
}
///***The values have been displayed

}

else //****The search.php didn't receive any data from a form
echo "No Data was submitted!";
?>


I suggest you take a basic course in PHP and MySQL, the following link may be useful
www.w3schools.com/PHP/DEfaULT.asP

Bowers007
01-12-2010, 10:11 PM
Thanks for the help. By the way this is not homework this is for my JOB. I told them with some help I could probably make this work.

Bowers007
01-13-2010, 08:01 PM
OK I have tried to figure out the issues. No luck. I need some help getting it to search by the Emp_Id that is with the employee name from this form.



<form action="SearchResultsTest.php" method="post">

<h4> Please Select a Employee: </h4>

<select name = "employee">
<option value=" ">Select Employee</option>
<option value="34">John Doe</option>
<option value="66">Jane Doe</option>
<option value="all">All Employees</option>
</select>

<br>
<br>

<input type="submit" value="SHOW TRAINING REPORT ">
</form>


Here is the PHP file SearchResultsTest.php



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

mysql_select_db("training_db", $con);

$result = mysql_query("SELECT * FROM employee");

echo "<table border='1'>
<tr>
<th>Emp_Id</th>
<th>LastName</th>
<th>FirstName</th>
<th>Dept</th>
</tr>";

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Emp_Id'] . "</td>";
echo "<td>" . $row['LastName'] . "</td>";
echo "<td>" . $row['FirstName'] . "</td>";
echo "<td>" . $row['Dept'] . "</td>";
echo "</tr>";
}
echo "</table>";

mysql_close($con);
?>


The problem seems to be here:


$result = mysql_query("SELECT * FROM employee");


And the fact I can't get it to search with the Emp_Id. When I run it it just echos the CODE. Someone Please HELP

Thanks

Bowers007
01-14-2010, 03:55 PM
I have uninstalled xampp and reinstalled it. Still not getting the SQL results. Anyone have any ideas? I think it should work or at least get something other that the code echoed. Here is what I have now:

TrainginDataBaseSearch.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>Search for a EmployeeTraining Record</title>
<meta name="keywords" content="HTML, CSS, PHP" /> </meta>
<link rel="stylesheet" type="text/css" href="TrainingDataBase.css">
</head>
<body>
<div align="center">
<p>
<img src="Images/dsHeaderLogo.png"
width="950" height="125">
<br>
<!-- SEARCH TRAINING RECORDS -->
<h1 align="center"><u><strong><font face="arial">Search for a EmployeeTraining Record</font></strong></u></h1>
</p>
<br>
<br>
<form action="SearchResults.php" method="post">
<h4> Please Select a Employee: </h4>
<select name = "employee">
<option value=" ">Select Employee</option>
<option value="34">John Doe</option>
<option value="66">Jane Doe</option>
</select>
<br>
<br>
<input type="submit" value="SHOW TRAINING REPORT ">
</form>
</div>
<br>
<center>
<a href="TrainingDataBaseAdd.php"><img src="Images/AddTrainingBtn.png" alt="Add New Person to DataBase" /></a>
</center>
<br>
<br>
<center>
<a href="TrainingDataBaseUpdate.php"><img src="Images/UpdateTrainingBtn.png" alt="Click Here to UPDATE a Training Record" /></a>
</center>
</body>
</html>



SearchResults.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>EmployeeTraining Record Results</title>
<meta name="keywords" content="HTML, CSS, PHP" /> </meta>
<link rel="stylesheet" type="text/css" href="TrainingDataBase.css">
</head>
<body>
<div align="center">
<p>
<img src="Images/dsHeaderLogo.png"
width="950" height="125">
<br>
<!-- SEARCH TRAINING RECORDS -->
<h1 align="center"><u><strong><font face="arial">EmployeeTraining Record Results</font></strong></u></h1>
</p>
<br>
<br>
<?php
if($_POST['employee'])
{
$emp_id = $_POST['employee'];
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("training_db", $con);
$result = mysql_query("SELECT * FROM employee WHERE Emp_Id=$emp_id");
echo "<table border='1'>
<tr>
<th>Emp_Id</th>
<th>LastName</th>
<th>FirstName</th>
<th>Dept</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['Emp_Id'] . "</td>";
echo "<td>" . $row['LastName'] . "</td>";
echo "<td>" . $row['FirstName'] . "</td>";
echo "<td>" . $row['Dept'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
}
else
{
echo '<form action="SearchResults.php" method="post">';
echo '<h4> Please Select a Employee: </h4>';
echo '<select name = "employee">';
echo '<option value=" ">Select Employee</option>';
echo '<option value="34">John Doe</option>';
echo '<option value="66">Jane Doe</option>';
echo '</select>';
echo '<br>';
echo '<br>';
echo '<input type="submit" value="SHOW TRAINING REPORT ">';
echo '</form>';
}
?>
</div>
</body>
</html>



This is driving me NUTS. Can someone tell me if the code is correct. I think if it's not I think it's real close but I can't get it to pull results from the training_db all I get when I try to pull a training record is

Emp_Id LastName FirstName Dept "; while($row = mysql_fetch_array($result)) { echo ""; echo "" . $row['Emp_Id'] . ""; echo "" . $row['LastName'] . ""; echo "" . $row['FirstName'] . ""; echo "" . $row['Dept'] . ""; echo ""; } echo ""; mysql_close($con); } else { echo '
'; echo '
Please Select a Employee:
'; echo ''; echo '
'; echo '
'; echo ''; echo '
'; } ?>

Someone please help. Thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum