Hi there,
I've been trying to figure out why my update script wont commit changes to the database. I'm building a simple call tracking web app for our technicians. Currently the view, add, and delete functions of the app work fine. The trouble I'm running into is when I want to update a record. I want the fields of the form to be auto filled from the current record. On the view page you enter the work order number and hit an update button. This is the update page:
<?php
$username="xxxxxxx";
$password="xxxxxxx";
$database="xxxxxxx";
$con=mysql_connect(localhost,$username,$password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db($database, $con);
$work_order=$_GET['work_order'];
$query="SELECT * FROM call_tracker WHERE work_order='$work_order'";
$result=mysql_query($query);
$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
$location=mysql_result($result,$i,"location");
$customer_name=mysql_result($result,$i,"customer_name");
$contact_number=mysql_result($result,$i,"contact_number");
$date_last_called=mysql_result($result,$i,"date_last_called");
$call_frequency=mysql_result($result,$i,"call_frequency");
$call_today=mysql_result($result,$i,"call_today");
$notes=mysql_result($result,$i,"notes");
++$i;
}
?>
<table border="0">
<form action="update.php" method="get">
<tr><td>Work Order:</td><td><? echo $work_order; ?></td></tr>
<tr><td>Location: </td><td><input type="text" name="location" value="<? echo $location; ?>"></td></tr>
<tr><td>Customer Name: </td><td><input type="text" name="customer_name" value="<? echo $customer_name; ?>"></td></tr>
<tr><td>Contact Number: </td><td><input type="text" name="contact_number" value="<? echo $contact_number; ?>"></td></tr>
<tr><td>Date Last Called: </td><td><input type="text" name="date_last_called" value="<? echo $date_last_called; ?>"></td></tr>
<tr><td>Call Frequency: </td><td><input type="text" name="call_frequency" value="<? echo $call_frequency; ?>"></td></tr>
<tr><td>Call Today: </td><td><input type="text" name="call_today" value="<? echo $call_today; ?>"></td></tr>
<tr><td>Notes: </td><td><input type="text" name="notes" value="<? echo $notes; ?>"></td></tr>
<tr><td></br><input type="button" onclick="window.location.href='view.php'" value="View Call Tracker"></input></td><td align="right"></br><input type="Submit" value="Update"></td></tr>
</form>
</table>
Once the fields are modified it gets sent onto this script to write the changes to the database:
<?php
$location=$_GET['location'];
$work_order=$_GET['work_order'];
$customer_name=$_GET['customer_name'];
$contact_number=$_GET['contact_number'];
$date_last_called=$_GET['date_last_called'];
$call_frequency=$_GET['call_frequency'];
$call_today=$_GET['call_today'];
$notes=$_GET['notes'];
$username="xxxxxxx";
$password="xxxxxxx";
$database="xxxxxxx";
$con=mysql_connect(localhost,$username,$password);
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("$database", $con);
$query="UPDATE call_tracker SET location='$location', customer_name='$customer_name', contact_number='$contact_number', date_last_called='$date_last_called', call_frequency='$call_frequency', call_today='$call_today', notes='$notes' WHERE work_order='$work_order'";
mysql_query($query);
echo "Record Updated";
?>
<br>
<form>
<input type="button" onclick="window.location.href='view.php'" value="View Call Tracker"></input>
</form>
I'm very new to PHP and SQL, but I've been using several different tutorials and I have a simpler version of this that just uses 2 fields and it works properly, I just can't seem to figure out why this doesn't work. Any help would be greatly appreciated.