Well, I am working on this ticketing system for a computer store and I ran into some problems, The database is not being updated for the customer, I've asked people and changed the code a lot, But cant seem to see what the problem is, The update querys seem alright, Their are also a few other small errors that you may come across. I would be greatfull if you could help me find a solution, I need to give to to someone tomarrow... I'll give you the current code.
CODE
<?php
require "database.php";
require "config.php";
$fname = $_REQUEST['firstname'];
$lname = $_REQUEST['lastname'];
$tech = $_REQUEST['tech'];
$problem = $_REQUEST['problem'];
$solution = $_REQUEST['solution'];
$phone1 = $_REQUEST['phone1'];
$phone2 = $_REQUEST['phone2'];
$address = $_REQUEST['address'];
$email = $_REQUEST['email'];
$date = date("d/m/Y");
$results = find_info($fname, $lname);
while($row = mysql_fetch_array($results))
{
$fnamedb = $row['first_name'];
$lnamedb = $row['last_name'];
$phone1db = $row['phone_1'];
$phone2db = $row['phone_2'];
$addressdb = $row['address'];
$emaildb = $row['email'];
$customer_id = $row['customer_id'];
}
//lookup_by_customer_id($customer_id);
//while($row = mysql_fetch_array($results))
//{
//
//}
$results = find_open_ticket($customer_id);
while($row = mysql_fetch_array($results))
{
$techdb = $row['technician'];
$costdb = $row['repair_cost'];
$problemdb = $row['problem'];
$solutiondb = $row['solution'];
$ticket_number = $row['ticket_number'];
}
?>
<html>
<head><TITLE>CEC Ticket System</TITLE>
<link REL="stylesheet" TYPE="text/css" href="css/master.css">
</head>
<body>
<?php include "mform.php"; ?>
<table width="363" border="0" align="center">
<tr>
<th width="357" scope="row"><form name="form1" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="get">
<div id="ticket" style="width: 90%">
<p align="center">First Name:
<input type="text" value="<?php echo $fnamedb ?>" name="firstname">
</p>
<p align="center">Last Name:
<input type="text" value="<?php echo $lnamedb ?>" name="lastname">
</p>
<p align="center">Phone 1:
<input type="text" value="<?php echo $phone1db ?>" name="phone1">
<p align="center">Phone 2:
<input type="text" value="<?php echo $phone2db ?>" name="phone2">
</p>
</p>
<p align="center">Email:
<input type="text" value="<?php echo $emaildb ?>" name="email">
</p>
<p align="center">Address:
<input type="text" value="<?php echo $addressdb ?>" name="address">
</p>
</p>
<p align="center">Technician:
<input type="text" value="<?php echo $techdb ?>" name="technician">
</p>
<p align="center">Cost:
<input type="text" value="<?php echo $costdb ?>" name="cost">
</p>
<p align="center">Problems
<textarea name="problem"><?php echo $problemdb ?></textarea>
</p>
<p align="center">Solution
<textarea name="solution"><?php echo $solutiondb ?></textarea>
</p>
<p align="center">
<input type="submit" name="submit" value="submit">
<input type="submit" name="close" value="Close Ticket">
</p>
</form></div>
<?php
if (isset($_REQUEST['submit']))
{
$sql = "UPDATE customers SET first_name=\"$fname\", last_name=\"$lname\", phone_1=\"$phone1\", phone_2=\"$phone2\", email=\"$email\", address=\"$address\" WHERE first_name=\"$fnamedb\" AND last_name=\"$lnamedb\" ";
$sql2 = "INSERT INTO tickets (customer_id, technician, problem, solution)
VALUES ('$customer_id', '$tech', '$problem', '$solution')";
$sql3 = "INSERT INTO customers (first_name, last_name, phone_1, phone_2, email, address)
VALUES ('$fname', '$lname', '$phone1', '$phone2', '$email', '$address')";
$sql4 = "UPDATE tickets SET customer_id=\"$customer_id\", technician=\"$tech\", problem=\"$problem\", solution=\"$solution\", repair_cost=\"$cost\" WHERE ticket_number=\"$ticket_number\" ";
$sql5 = "UPDATE tickets SET status=0 WHERE ticket_number=\"$ticket_number\" ";
echo("RESULTS<br/>");
$ticket = "SELECT * FROM tickets WHERE customer_id=\"$customer_id\" AND ticket_number=\"$ticket_number\" ";
$result = mysql_query($ticket);
if( mysql_numrows($result)==0 )
{
if (!mysql_query($sql2))
{
die('Error: ' . mysql_error());
}
} else {
if (!mysql_query($sql4))
{
die('Error: ' . mysql_error());
}
}
$customer = "SELECT * FROM customers WHERE first_name=\"$fnamedb\" AND last_name=\"$lnamedb\" ";
$result = mysql_query($customer);
echo mysql_numrows($result);
if( mysql_numrows($result)==0 )
{
if (!mysql_query($sql3))
{
die('Error: ' . mysql_error());
}
else
{
echo "Success!";
}
}
} else {
if (!mysql_query($sql))
{
die('Error: ' . mysql_error());
}
else
{
echo "Success!";
}
}
if (isset($_REQUEST['close']))
{
if (!mysql_query($sql5))
{
die('Error: ' . mysql_error());
}
}
?>
</th>
</tr>
</table>
<br/>
</body>
<head>
Thank You.