将数据更新到mySQL数据库时遇到问题。我连接数据库很好,可以很好地提取信息,但为什么不发回信息并存储呢?如果用户想修改这样的数据,下面是php
<?php
if(isset($_POST['Modify']))
{
if(!empty($_REQUEST['rep_num']))
{
print "Nothing was entered." ;
} else {
$rep_num=$row['REP_NUM'];
$last_name=$row['LAST_NAME'];
$first_name=$row['FIRST_NAME'];
$street=$row['STREET'];
$city=$row['CITY'];
$state=$row['STATE'];
$zip=$row['ZIP'];
$commission=$row['COMMISSION'];
$rate=$row['RATE'];
$error = 0;
// if($rep_num == NULL ||
// $last_name==NULL||
// $first_name==NULL||
// $street==NULL||
// $city==NULL||
// $state==NULL||
// $zip==NULL||
// $commission==NULL||
// $rate==NULL)
// {
// print "All fields must be completed in order to carry on!";
// $error++;
// }
if(empty($_REQUEST['rep_num']) || empty($_REQUEST['last_name']) || empty($_REQUEST['first_name']) || empty($_REQUEST['street']) || empty($_REQUEST['city']) || empty($_REQUEST['state']) || empty($_REQUEST['zip']) || empty($_REQUEST['commission']) || empty($_REQUEST['rate']))
{
print "There is information missing from your form.";
}
if(!is_numeric($zip)&&$zip!=NULL)
{
print "Invalid Zip Code";
$error++;
}
$state_length = strlen($state);
if(($state_length != 2 || is_numeric($state))&&$state!=NULL)
{
print "Invalid State";
$error++;
}
// if ($error != 0)
// {
// echo "<p>The data for Sales Representative ".$num." is displayed below</p>";
// }
elseif($error==0)
{
$new_state = strtoupper($state);
$query = mysql_query("UPDATE REP SET REP_NUM ='$rep_num', FIRST_NAME = '$first_name', LAST_NAME ='$last_name', STREET ='$street', CITY ='$city', STATE ='$new_state', ZIP ='$zip', COMMISSION = '$commission', RATE = '$rate' WHERE REP_NUM='$rep_num'");
$viewquery= "SELECT * FROM REP WHERE REP_NUM = '$rep_num'";
if($r=mysql_query($viewquery))
{
echo "<center>";
echo "<table border = '2' cellpadding = '5' style='font-size: 12px; border-color: white; border-style: outset; padding: 5px; text-align:center'>
<tr bgcolor='gray'>
<th>Sales Rep Number</th>
<th>Sales Rep Full Name</th>
<th>Street</th>
<th>City</th>
<th>State</th>
<th>Zip</th>
<th>Commission</th>
<th>Rate</th>
</tr>";
$row=mysql_fetch_array($r);
echo"<p>Modification successful. <br />The modified data for Sales Representative number ".$row['REP_NUM']." is displayed below.</p>";
echo"<tr>";
echo"<td>" .$row['REP_NUM'] ."</td>";
echo"<td>" .$row['LAST_NAME'] ."</td>";
echo"<td>" .$row['STREET'] ."</td>";
echo"<td>" .$row['CITY'] ."</td>";
echo"<td>" .$row['STATE'] ."</td>";
echo"<td>" .$row['ZIP'] ."</td>";
echo"<td>" .$row['COMMISSION'] ."</td>";
echo"<td>" .$row['RATE'] ."</td>";
echo"</tr>";
echo "</table>";
echo"</center>";
echo"<br /><br />";
}
}
}
}
?>