Hello everyone, I am trying to update a database as well as insert information into the database and this is what I created to do so. Only, I am getting the email and its not updateding the database...any ideas?

<?php
if ($_POST['submit']) //if the Submit button pressed
  {
                      $con = mysqli_connect("localhost","root","pass","testdb");
                       if (mysqli_connect_errno())
                               {
                                      echo "Failed to connect to MySQL:" . mysqli_connect_error();
                               }

$sql = "INSERT INTO computerdb (name, email, ticket, phone, computerpass, findus, status, notes )
                       VALUES ('".mysqli_real_escape_string($con,$_POST['name'])."','".mysqli_real_escape_string($con,$_POST['email'])."','".mysqli_real_escape_string($con,$_POST['ticketnumber'])."','".mysqli_real_escape_string($con,$_POST['phone'])."','".mysqli_real_escape_string($con,$_POST['password'])."','".mysqli_real_escape_string($con,$_POST['referredby'])."', 'Pending', '".date('m/d/Y H:i:s'). ": Work has started on your computer')";

                       if (!mysqli_query($con,$sql))
                        {
                             die('Error: ' . mysqli_error($con));
                        }
                                $blah = $_GET['computerid'];
                                $cpuname    =    mysqli_real_escape_string($con,$_POST['cpuname']);
                                $sn          =    mysqli_real_escape_string($con,$_POST['sn']); 
                                $model    =    mysqli_real_escape_string($con,$_POST['model']);
                                $brand       =    mysqli_real_escape_string($con,$_POST['brand']);
                                $hdd    =    mysqli_real_escape_string($con,$_POST['hdd']);
                                $memory    =    mysqli_real_escape_string($con,$_POST['memory']);
                                $type    =    mysqli_real_escape_string($con,$_POST['type']);

                             $query = "UPDATE custcomp SET cpuname = '$cpuname', sn = '$sn', model = '$model', brand = '$brand', hdd =  '$hdd', memory = '$memory', type = '$type' WHERE id = '$blah'";

                             if (!mysqli_query($con,$query))
                        {
                                die('Error: ' . mysqli_error($con));
                        }else{

            //if data is inserted successfully, send email
                       $to = $_POST['email'];
                       $url = "http://omitted.com/newportal/do_search.php?query=";
                       $ticket = $_POST['ticketnumber'];

                       $header = 'MIME-Version: 1.0' . "\r\n";
                        $header .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
                        $header .= "From: omitted. <tickets@omitted.com>" . "\r\n";
                       $subject = "Ticket Number ".$_POST['ticketnumber'];
                       $body .= "<html><body>"."\n";
                    $body .= "Hello ".$_POST['name'].",<br>
                        <br>";
                    $body .= "Thank you for stopping by today.<br><br>"."\n";
                    $body .= "The information below is used to check on the status of your computer.<br>"."\n";
                    $body .= "Check Computer Status: <a href=\"".$url.$ticket."\">".$ticket."</a><br><br>"."\n";
                    $body .= "Be sure to like us on <a href=\"http://www.facebook.com/omitted\"><img                                                                                                              src=\"http://www.omitted.com/ticketgen/images/facebook.png\" width=\"30\" height=\"30\"></a> and <a href=\"http://www.twitter.com/omitted\"><img src=\"http://www.omitted.com/ticketgen/images/twitter.png\" width=\"50\" height=\"30\"></a>!". "\n";
                    $body .= "<br><br><br>Sincerly, <br><br><img style=\"border:none; text-decoration:none;\" src=\"http://www.omitted.com/ticketgen/images/signature.png\" alt=\"Patrick Kershner\" />"."\n";
                    $body .= "</html></body>"."\n";
                       $sent = mail($to, $subject, $body, $header);
                       if($sent)
                               header('Location: http://www.omitted.com/newportal/new_ticket.php?success=1&redir=1');
                       else
                               {print "There was an error sending the mail";}

                       mysqli_close($con);
                        }
        }
?>

I think I figured out what is going on...In the code for HTML I have a dropdown that they select the computer from and modifies the code after its already been generated. Since the code is not present during the initial loading period, it therefore does not exist. I am now unsure of how to get the code to read the modified html code that gets generated afterwards.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.