Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 132,674 PHP Programmers for FREE! Get instant access to thousands of PHP experts, tutorials, code snippets, and more! There are 1,204 people online right now. Registration is fast and FREE... Join Now!




Not Updating Database?

 
Reply to this topicStart new topic

Not Updating Database?

Addiction2Code
post 1 Aug, 2007 - 10:21 AM
Post #1


New D.I.C Head

*
Joined: 19 Dec, 2006
Posts: 39


My Contributions


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.
User is offlineProfile CardPM

Go to the top of the page

Martyr2
post 1 Aug, 2007 - 10:36 AM
Post #2


Programming Theoretician

Group Icon
Joined: 18 Apr, 2007
Posts: 5,062



Thanked 175 times

Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions


First of all, are you getting any error messages? If so, what are they? If you are not getting any error messages, I suggest you put in some echo statements in spots like after the isset($_REQUEST['submit']) { to make sure you are getting into that if statement and after each query to see if they are indeed executing.

Basically you need to trace the path of execution to see if all the values you think are being put into your variables is indeed in your variables. Check things like $result to see if it is a valid result, echo the values of $sql, $sql4 and $sql5 before you use them to make sure the updates statements say what they are meant to say. That last trick is key because you could have a valid Update statement and still not update anything (if your statement has the wrong values in the where clause it will either update everything ... bad... or it will update nothing because no rows match). I am also assuming your ticket_number is an auto_incrementing field used as the primary key?

Do some of that and let us know the outcome.

This post has been edited by Martyr2: 1 Aug, 2007 - 10:41 AM
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 11/23/08 06:23AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month