I was able to copy, paste and modify a reasonably working interactive website together.
However, one of the forms does not work the way I want it to. It is supposed to update a table in the MySQL database and consists of two drop-down boxes and three text fields. The first drop down boxes is populated by a MySQL query (which works fine) and the other drop-down box has a choice of three values.
If I don't touch the first drop-down box, everything will update correctly in the first choice. But if I choose a different selection (the entry in the second row, etc.) I still will get the message "Record Updated" but nothing will actually happen to the table?
After googling for the past 4 to 5 days to find a solution, reading up on hundreds of articles in order to make sense of it all and countless trial and error tests, I have to admit defeat and beg for help!
I would highly appreciate if somebody could have a look at my code and tell me what I'm doing wrong in layman's terms, S. all in what I have to work with is common sense, logic but unfortunately no knowledge.
Here is the code for the form:
<form action="update_sh.php" method="post">
<p>
<th ALIGN=left><font size='2'>Select Property</th>
<br>
<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("dbname", $con);
$result = mysql_query("SELECT * FROM tablename");
echo "<select name='property'>";while ($row = mysql_fetch_array($result)) { echo "<option value='" . $row['prop'] . "'>" . $row['prop'] . "</option>";}echo
"</select>";?>
</p>
<p>
What is your Position?
<br>
<select name="position">
<option value="">Select...</option>
<option value="Executive Chef">Executive Chef</option>
<option value="Exec. Sous Chef">Exec. Sous Chef</option>
<option value="Pastry Chef">Pastry Chef</option>
</select>
</p>
Your Full Name: <br>
<input type="text" name="chef" size="45"><br>
E-mail: <br>
<input type="text" name="chefe" size="45"><br>
Phone: <br>
<input type="text" name="chefn" size="45"><br>
<input type="Submit">
</form>
[code/]
And here is the PHP code for the update.php file:
[code]
<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("dbname", $con);
$ud_prop=$_REQUEST['property'];
$ud_position=$_REQUEST['position'];
$ud_chef=$_POST['chef'];
$ud_chefe=$_POST['chefe'];
$ud_chefn=$_POST['chefn'];
$ud_sous=$_POST['chef'];
$ud_souse=$_POST['chefe'];
$ud_sousn=$_POST['chefn'];
$ud_patt=$_POST['chef'];
$ud_patte=$_POST['chefe'];
$ud_pattn=$_POST['chefn'];
if ($ud_position=='Executive Chef')
{
$query="UPDATE tablename SET id='Null', posie='".$ud_position."', chef='$ud_chef', chefe='$ud_chefe', chefn='$ud_chefn' WHERE prop='$ud_prop'";
mysql_query($query);
echo "Record Updated";
mysql_close($con);
}
elseif ($ud_position=='Exec. Sous Chef')
{
$query="UPDATE tablename SET id='Null', posis='$ud_position', sous='$ud_chef', souse='$ud_chefe', sousn='$ud_chefn' WHERE prop='$ud_prop'";
mysql_query($query);
echo "Record Updated";
mysql_close($con);
}
elseif ($ud_position=='Pastry Chef')
{
$query="UPDATE tablename SET id='Null', posip='$ud_position', patt='$ud_chef', patte='$ud_chefe', pattn='$ud_chefn' WHERE prop='$ud_prop'";
mysql_query($query);
echo "Record Updated";
mysql_close($con);
}
elseif ($ud_position=='Select...')
{
echo "Please click your browsers back button, select your position and try again -- ";
}
?>
Thank you in advance!

New Topic/Question
Reply



MultiQuote





|