PHP MySQL Help

  • (3 Pages)
  • +
  • 1
  • 2
  • 3

43 Replies - 2235 Views - Last Post: 18 January 2010 - 10:17 AM Rate Topic: -----

#1 James Bond C++ Spy  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 132
  • Joined: 03-October 07

PHP MySQL Help

Posted 11 January 2010 - 09:59 AM

Good Day, I am trying to create a Training database using PHP and MySQL. This needs to be able to search by employee name and return the dates of the training 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 written a SQL script to insert into the tables to build 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 not tried to use it yet as I am sure there are several issues. Here is what I have so far:


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 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">
<p>
<img src="Images/dsHeaderLogo.png"
width="950" height="125">

<br>

<!--  SEARCH PRODUCT DHR -->

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

<br>
<br>

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

<br>
<br>

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

</div> 

<br>

<?php

if (!empty($_GET['employee']) || !empty($_GET['sort'])){
$DBConnect = mysql_connect("localhost", "root");
if (!$DBConnect)
{
die('Could not connect: ' . mysql_error());
  }
  mysql_select_db("training_db", $DBConnect);
  $employee = $_GET['employee'];
  
  if ($make == "all")
  $result = "SELECT * FROM Emp_Id = '$employee'";
  $resulttraining = mysql_query($result);
  
//Display Results in a Table

echo "<table align='center' table border='8'>
<tr>
<th>Employee Id</th>
<th>First Name</th>
<th>Last Name</th>
<th>Department</th>
<th>Diversity / Sexual Haarassment</th>
<th>BBP</th>
<th>LOTO</th>
<th>Haz Comm</th>
<th>PPE</th>
<th>Evacuation</th>
<th>ISO 13485</th>
<th>ISO 9001</th>
<th>Quality DHR</th>
<th>Orientation</th>
<th>Work Instructions</th>
<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>
<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 "<td align='center'>" . $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>"; 
  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>";

?> 

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




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 PERSON to theTraining 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 to 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);
?> 





Here is the Tables in the SQL Tables:

--EMPLOYEE TABLE
CREATE TABLE employee
(
Emp_Id int NOT NULL,
LastName varchar(255) NOT NULL,
FirstName varchar(255),
Dept varchar(255),
)


--ANNUAL TABLE
CREATE TABLE annual
(
Emp_Id int NOT NULL,
diversity varchar(10) NOT NULL,
bbp varchar(10),
loto varchar(10),
hazcomm varchar(10),
ppe varchar(10),
evacuation varchar(10),
)


--QUALITY TABLE
CREATE TABLE quality
(
Emp_Id int NOT NULL,
iso13485 varchar(10),
iso9001 varchar(10),
qualitydhr varchar(10),
orientation varchar(10),
workinstructions varchar(10),
)


--ENDO TABLE
CREATE TABLE endo
(
Emp_Id int NOT NULL,
handledrilling varchar(10),
assembly varchar(10),
cg varchar(10),
fluter varchar(10),
labels varchar(10),
shafting varchar(10),
molding varchar(10),
laser varchar(10),
tipping varchar(10),
qc5000 varchar(10),
calibration varchar(10),
staking varchar(10),
stamp varchar(10),
)


--MACHINE SHOP TABLE
CREATE TABLE ms
(
Emp_Id int NOT NULL,
mazak varchar(10),
fadal varchar(10),
screw varchar(10),
forklift varchar(10),
)




Thanks for all your help

This post has been edited by James Bond C++ Spy: 12 January 2010 - 06:55 AM


Is This A Good Question/Topic? 0
  • +

Replies To: PHP MySQL Help

#2 BenignDesign  Icon User is offline

  • holy shitin shishkebobs
  • member icon




Reputation: 5936
  • View blog
  • Posts: 10,346
  • Joined: 28-September 07

Re: PHP MySQL Help

Posted 11 January 2010 - 10:49 AM

Rule #1: Test as you go. This will save you innumerable headaches down the road. If you test and retest all along the way, errors that start out as little speed bumps never have time to turn into brick walls.

This post has been edited by BenignDesign: 11 January 2010 - 10:49 AM

Was This Post Helpful? 0
  • +
  • -

#3 James Bond C++ Spy  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 132
  • Joined: 03-October 07

Re: PHP MySQL Help

Posted 12 January 2010 - 07:03 AM

Thanks for the tip but I really need some help bring this all together. Can someone please give me some help?

Thanks
Was This Post Helpful? 0
  • +
  • -

#4 thinspirit  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 43
  • Joined: 12-January 10

Re: PHP MySQL Help

Posted 13 January 2010 - 01:02 AM

I think what BenignDesign is referring to is. Give'r a go! Tell us what it's doing and what it's not doing. Try getting it to do something specific. See what PHP errors pop up or when information goes missing.

Beginning to learn how to program in PHP is 20% writing code and 80% figuring out why it's not doing exactly what you want it to do. Once you figure it out, your experiences will dictate down the road you won't make the same mistakes again.
Was This Post Helpful? 0
  • +
  • -

#5 James Bond C++ Spy  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 132
  • Joined: 03-October 07

Re: PHP MySQL Help

Posted 13 January 2010 - 08:14 AM

OK I have given it a go. The TrainingDataBaseSearch.php page comes up and looks exactly like I want. I can select an employee from the pull down menu. When I click the "show training report" button it goes to the SearchResults.php page as it should but I get no results from the database only the field names that I am echoing for the results display table and the. This is my first hurdle.

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="post">
<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>



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


This post has been edited by James Bond C++ Spy: 13 January 2010 - 08:17 AM

Was This Post Helpful? 0
  • +
  • -

#6 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,436
  • Joined: 23-August 08

Re: PHP MySQL Help

Posted 13 January 2010 - 08:27 AM

So the "offending query" is this one then?
$query = mysql_query("SELECT * FROM     employee WHERE employee = Emp_Id");

What is Emp_Id? If you're trying to load all employees, why would you be using a WHERE clause anyway?
Was This Post Helpful? 0
  • +
  • -

#7 James Bond C++ Spy  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 132
  • Joined: 03-October 07

Re: PHP MySQL Help

Posted 13 January 2010 - 08:56 AM

What I have tried to do is have the employee ID (Emp_Id) as the common field in the tables so when I select an employee name from the pull down menu it will pull results related by the Emp_Id (34)

<option value="34">Joe Blow</option>


This post has been edited by James Bond C++ Spy: 13 January 2010 - 08:57 AM

Was This Post Helpful? 0
  • +
  • -

#8 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6039
  • View blog
  • Posts: 23,436
  • Joined: 23-August 08

Re: PHP MySQL Help

Posted 13 January 2010 - 09:38 AM

Wait, where is $resulttraining here
while($row = mysql_fetch_array($resulttraining))

getting populated? I see it in your OP but not in the most recent.
Was This Post Helpful? 0
  • +
  • -

#9 James Bond C++ Spy  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 132
  • Joined: 03-October 07

Re: PHP MySQL Help

Posted 13 January 2010 - 12: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","dsdental");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("training_db", $con);

$person = $_POST['employee'];

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

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 I think because i'm not getting any results:
$person = $_POST['employee'];

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



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

This post has been edited by James Bond C++ Spy: 13 January 2010 - 01:06 PM

Was This Post Helpful? 0
  • +
  • -

#10 BenignDesign  Icon User is offline

  • holy shitin shishkebobs
  • member icon




Reputation: 5936
  • View blog
  • Posts: 10,346
  • Joined: 28-September 07

Re: PHP MySQL Help

Posted 13 January 2010 - 01:06 PM

1. Have you double and triple checked your database? Are all the names spelled EXACTLY alike (ie, caps to caps, lowers to lowers, underscore to underscore, etc)??

2.
$query = mysql_query("SELECT * FROM     employee WHERE employee = Emp_Id");

Is Emp_Id a field in the employee table or is employee a field in the employee table or both? And what data type(s) is/are it/they?

3. If you have the employee information stored in a database, why are you hard coding employee names into your selection box?

4. Where does the code go after you hit "submit"? How are you passing variables? I see "method='post'", but I don't see any actual posting of data.
Was This Post Helpful? 0
  • +
  • -

#11 James Bond C++ Spy  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 132
  • Joined: 03-October 07

Re: PHP MySQL Help

Posted 13 January 2010 - 01:12 PM

Thanks for taking the time to help..

1. yes I have checked the database
2. The Emp_Id is a field in the employee table
3. I am hard coding the names so someone can select the employee by name not ID #
4. I just changed the code while you were responding. When I hit submit it shows the "code" in the PHP

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

Here is the code now:


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







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

mysql_select_db("training_db", $con);

$person = $_POST['employee'];

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

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




Once again thanks for the help

This post has been edited by James Bond C++ Spy: 13 January 2010 - 01:14 PM

Was This Post Helpful? 0
  • +
  • -

#12 BenignDesign  Icon User is offline

  • holy shitin shishkebobs
  • member icon




Reputation: 5936
  • View blog
  • Posts: 10,346
  • Joined: 28-September 07

Re: PHP MySQL Help

Posted 13 January 2010 - 01:16 PM

Are you running this from a server or from your PC?

This post has been edited by BenignDesign: 13 January 2010 - 01:19 PM

Was This Post Helpful? 0
  • +
  • -

#13 James Bond C++ Spy  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 132
  • Joined: 03-October 07

Re: PHP MySQL Help

Posted 13 January 2010 - 01:28 PM

I am using xampp on my laptop
Was This Post Helpful? 0
  • +
  • -

#14 BenignDesign  Icon User is offline

  • holy shitin shishkebobs
  • member icon




Reputation: 5936
  • View blog
  • Posts: 10,346
  • Joined: 28-September 07

Re: PHP MySQL Help

Posted 13 January 2010 - 01:36 PM

Are you able to run ANY php scripts from it?
Was This Post Helpful? 0
  • +
  • -

#15 James Bond C++ Spy  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 132
  • Joined: 03-October 07

Re: PHP MySQL Help

Posted 13 January 2010 - 02:01 PM

When I run this :

<?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");

while($row = mysql_fetch_array($result))
  {
  echo $row['FirstName'] . " " . $row['LastName'];
  echo "<br />";
  }

mysql_close($con);
?> 





I get this:

"; } mysql_close($con); ?>
Was This Post Helpful? 0
  • +
  • -

  • (3 Pages)
  • +
  • 1
  • 2
  • 3