I am working on a database search where the customer can search for a specific id number and then update the record. The customer will initially enter a company name and id. Depending on the company name a specific table will be searched and the record displayed. From this form the customer can then update the record and display the updated recorded.
The initial search is fine. The form does not update and displays the original data.
I have a current script to enter the initial information to the database that is basically the same as this one as far as the if statements to select the correct table and it works fine. I have tried removing everything except a single update statement and the table still didn't update. I can update from a telnet command line. I'm sure I'm missing something simple.
Any help is appreciated.
Gina
<?php
if ($submit AND $company AND $giftcert) {
echo "$company AND $giftcert";
// update form
$db = mysql_connect("xxxx", "xxxx", "xxx")
or die ("Failed to connect to MySQL.");
mysql_select_db("xxxx",$db)
or die ("Could not open database.");
////// insert table based on company name
if ($company == 'comp1') {
$sql = "UPDATE customer_ap
SET name='$name',
address='$address',
city='$city',
state='$state',
zip='$zip',
address='$address',
phone='$phone',
phone2='$phone2',
email='$email',
connect='$connect',
credit='$credit',
qualification='$qualification',
activedate='$activedate',
saletype='$saletype',
chargebkdt='$chargebkdt',
Where giftcert='$giftcert' ";
$resultupd = mysql_query($sql);
$verify = mysql_query("SELECT * FROM customer_ap
WHERE giftcert='$giftcert'
");
}
if ($company == 'comp2') {
$sql = "UPDATE customer_rb
SET name='$name',
address='$address',
city='$city',
state='$state',
zip='$zip',
address='$address',
phone='$phone',
phone2='$phone2',
email='$email',
connect='$connect',
credit='$credit',
qualification='$qualification',
activedate='$activedate',
saletype='$saletype',
chargebkdt='$chargebkdt',
Where giftcert='$giftcert' ";
$resultupd = mysql_query($sql);
$verify = mysql_query("SELECT * FROM customer_rb
WHERE giftcert='$giftcert'
");
}
////// insert table based on company name
if ($company == 'comp3') {
$sql = "UPDATE customer_mhr
SET name='$name',
address='$address',
city='$city',
state='$state',
zip='$zip',
address='$address',
phone='$phone',
phone2='$phone2',
email='$email',
connect='$connect',
credit='$credit',
qualification='$qualification',
activedate='$activedate',
saletype='$saletype',
chargebkdt='$chargebkdt',
Where giftcert='$giftcert' ";
$resultupd = mysql_query($sql);
$verify = mysql_query("SELECT * FROM customer_mhr
WHERE giftcert='$giftcert'
");
}
if (mysql_num_rows($verify)==0)
{
echo "<font face=arial, helvetica, sans-serif size=3 color=red>
<b>No Customers Match query.</b></font>";
exit;
} else{
////variable names
$giftcert=mysql_result($verify,0,"giftcert");
$name=mysql_result($verify,0,"name");
$address=mysql_result($verify,0,"address");
$city=mysql_result($verify,0,"city");
$state=mysql_result($verify,0,"state");
$zip=mysql_result($verify,0,"zip");
$phone=mysql_result($verify,0,"phone");
$phone2=mysql_result($verify,0,"phone2");
$email=mysql_result($verify,0,"email");
$date=mysql_result($verify,0,"date");
$connect=mysql_result($verify,0,"connect");
$credit=mysql_result($verify,0,"credit");
$qualification=mysql_result($verify,0,"qualification");
$activedate=mysql_result($verify,0,"activedate");
$saletype=mysql_result($verify,0,"saletype");
$chargebkdt=mysql_result($verify,0,"chargebkdt");
// create form to update information
}
echo "<font face='Arial, Helvetica, sans-serif' size='3'> ";
echo "Gift Certificate: <b>$giftcert</b> ";
echo "Issued By: <b>$company</b> On: <b>$date</b> <br /> ";
echo "Customer Name: $name <br />";
echo "Address: $address <br />";
echo "City: $city <br /> ";
echo "State: $state <br /> ";
echo "Zip Code: $zip <br /> ";
echo "Phone: $phone <br /> ";
echo "Phone 2: $phone2 <br /> ";
echo " Email: $email <br /> ";
echo "Connections Requested: $connect <br /> ";
echo "Established Credit: $credit <br /> ";
echo "Qualification: $qualification <br /> ";
echo "Account Activated: $activedate <br/> ";
echo "Sale Type: $saletype <br /> ";
echo "Charge Back Date: $chargebkdt <br /> ";
echo "</font> ";
} else {
echo "Form cannot be updated at this time. Please press your browsers back button and re-submit. ";
}
?>