Update Query Not Working
Posted: Sat May 17, 2008 11:13 pm
I'm trying to write some php script that will on the first page ask for the record to alter by throwing all the id's into a drop down select menu (which works), it then includes a php file that will display all the data in a form's text fields below with an edit button- which when pressed should include another php page that will post all the fields and update the database with the new information. Unfortunuatly, everything is working but updating the database.
Here's my code:
Page 1:
PHP Page 2 (inputBrotherRecord.php)
PHP Page 3 (editBrotherRecord.php)
Here's my code:
Page 1:
Code: Select all
<p>
<form method="post">
<table>
<tr>
<td>
PIN      
</td>
<td>
<select name='pin'>
<?php
include 'LoginDb.php';
include 'UseActives.php';
$query="SELECT pin from brothers";
$pins=mysql_query($query)
or die('Query Database failed.');
while($row = mysql_fetch_row($pins))
{
$pin = $row[0];
echo '<option>';
echo $pin;
echo'</option>';
};
while(list($pin) = mysql_fetch_array($pins,MYSQL_NUM))
{
$pin=$pin;
};
?>
</select>
</td>
<td>
      <input name="select" type="submit" value="Select Brother">
</td>
</tr>
</form>
</table>
</p>
<?php
if(isset($_POST['select']))
{
include 'inputBrotherRecord.php';
}
?>
<?php
include 'CloseDb.php';
?>Code: Select all
<?php
$pin=$_POST['pin'];
include 'LoginDb.php';
include 'UseActives.php';
$query1="SELECT name,street1,street2,home,zip,hNumber,schNumber,major ".
"FROM brothers ".
"WHERE pin='$pin'";
$result = mysql_query($query1);
while(list($name,$street1,$street2,$home,$zip,$hNumber,$schNumber,$major) = mysql_fetch_array($result,MYSQL_NUM))
{
?>
<h2>
PIN <?php echo $pin;?>
</h2>
<p>
<table>
<form method="post">
<tr>
<td>
Name
</td>
<td>
<input id='name' type="text" value="<?php echo $name;?>">
</td>
</tr>
<tr>
<td>
 
</td>
</tr>
<tr>
<td>
Address Line 1
</td>
<td>
<input name='street1' type="text" value="<?php echo $street1;?>">
</td>
</tr>
<tr>
<td>
 
</td>
</tr>
<tr>
<td>
Address Line 2
</td>
<td>
<input name='street2' type="text" value="<?php echo $street2;?>">
</td>
</tr>
<tr>
<td>
 
</td>
</tr>
<tr>
<td>
City, State
</td>
<td>
<input name='home' type="text" value="<?php echo $home;?>">
</td>
</tr>
<tr>
<td>
 
</td>
</tr>
<tr>
<td>
ZIP Code
</td>
<td>
<input name='zip' type="text" value="<?php echo $zip;?>">
</td>
</tr>
<tr>
<td>
 
</td>
</tr>
<tr>
<td>
Home Number
</td>
<td>
<input name='hNumber' type="text" value="<?php echo $hNumber;?>">
</td>
</tr>
<tr>
<td>
 
</td>
</tr>
<tr>
<td>
School Number
</td>
<td>
<input name='schNumber' type="text" value="<?php echo $schNumber;?>">
</td>
</tr>
<tr>
<td>
 
</td>
</tr>
<tr>
<td>
Major
</td>
<td>
<input name='major' type="text" value="<?php echo $major;?>">
</td>
</tr>
</table>
</p>
<?php
}
?>
<p>
<input name="edit" type="submit" value="Edit Record"> 
<input name="delete" type="submit" value="Delete Record">
<?php
if(isset($_POST['edit']))
{
include 'editBrotherRecord.php';
}
?>
</p>
<p>
<a href="\BrotherMgt.php">Back to Brother Management Menu</a>
</p>Code: Select all
<?php
include 'LoginDb.php';
include 'UseActives.php';
$name=$_POST["name"];
$street1=$_POST['street1'];
$street2=$_POST['street2'];
$home=$_POST['home'];
$zip=$_POST['zip'];
$hNumber=$_POST['hNumber'];
$schNumber=$_POST['schNumber'];
$major=$_POST['major'];
$query2="UPDATE brothers ".
"SET name='$name',street1='$street1',street2='$street2',home='$home',".
"zip='$zip',hNumber='$hNumber',schNumber='$schNumber',major='$major' ".
"WHERE pin='$pin'";
mysql_query($query2)
or die('Update failed.');
?>