I have a database with two tables: "Pay Codes" and "Worksheet". Worksheet is an invoice of sorts containing 13 fields of pay codes in the fields of First, S1, S2, S3, . . .
"Pay Codes" has three fields: "Code", "Description", and "Price". I'm trying to write a PHP routine that takes "First", "S1", . . . from Worksheet and pulls the appropriate data from Pay Codes. What I'm aiming for is when a user enters "AC7" in the "First" field in Worksheet, MySQL returns the "Description" and "Price" for "Code" This is what I've cobbled together from www.w3schools.com/PHP/php_mysql_where.asp
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("BTS", $con);
$sql="INSERT INTO Worksheet (Date, TechNum, Job, Account, Address, Equipment, First, S1, S2, S3, S4, S5, S6, S7, S8, S9, S10, S11, S12, COD)
VALUES
('$_POST[Date]', '$_POST[TechNum]','$_POST[Job]','$_POST[Account]','$_POST[Address]','$_POST[Equipment]','$_POST[First]','$_POST[S1]','$_POST[S2]','$_POST[S3]','$_POST[S4]','$_POST[S5]','$_POST[S6]','$_POST[S7]','$_POST[S8]','$_POST[S9]','$_POST[S10]','$_POST[S11]','$_POST[S12]','$_POST[COD]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
echo "<br />";
echo First;
echo "<br />";
$result = mysql_query("SELECT * FROM 'Pay Codes'
WHERE 'Code' = 'First'");
echo $result;
while($row = mysql_fetch_array($result))
{
echo $row['Code'] . " " . $row['Description'] . " " . $row['Price'];
echo "<br />";
}
echo $row;
mysql_close($con)
?>
When the routine runs after clicking the "Submit" button, MySQL responds with the following: "Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /Applications/XAMPP/xamppfiles/htdocs/insert.php on line 30" Line 30 is the "while" statement
Would somebody translate all this into English?