I'm having heaps of trouble getting one of my PHP/MySQL queries to work for some reason (and the funny thing is there are plenty that are identical to it all the way through the site) so I'm wondering if someone can spot the problem. (I've basically torn all the code apart trying to work it out and have changed values that are being submitted, etc to try and get it to work, so I'm tearing my hair out now!)
Code: $staffID = $_POST['staffID'];
$date = date("Y-m-d h:i:s");
$sql2 = "INSERT INTO Order (date, staffID) 
         VALUES ('$date', '$staffID')";
$result2 = mysqli_query($cxn, $sql2)
           or die ("Couldn't execute insert into order query.");
As it's not working, I keep getting "Couldn't execute insert into order query."
The MySQL database is named Order, and has orderID, date and staffID. orderID is int(8 ), unsigned zerofill and autoincrement. date is datetime, and staffID is int(4) unsigned zerofill. Staff members enter the zeros in their staffID when putting their details into the form (so would enter 0004).
Here's the full code:
createorder.php
Code: <?php
   include("credentials.inc");
   
   switch (@$_POST['do']) {
   
       case "neworder":
      
       $cxn = mysqli_connect($host, $user, $password, $dbname) 
               or die ("Connection failed.");
   
       $staffID = $_POST['staffID'];
      $sku = $_POST['sku'];
      $quantity = $_POST['quantity'];
       
      $sql = "SELECT staffID FROM Staff
                WHERE staffID = '$staffID'";
        $result = mysqli_query($cxn, $sql)
                  or die ("Couldn't execute staff query.");
        $num = mysqli_num_rows($result);
      
      if ($num > 0) { //staff member found
      
          $date = date("Y-m-d h:i:s");
                
         $sql2 = "INSERT INTO Order (date, staffID) 
                VALUES ('$date', '$staffID')";
          $result2 = mysqli_query($cxn, $sql2)
                   or die ("Couldn't execute insert into order query.");
         
         $sql3 = "SELECT orderID FROM Order
                  WHERE date = '$date'";
         $result3 = mysqli_query($cxn, $sql3)
                     or die ("Couldn't execute select from order query.");
         $rowname = mysqli_fetch_assoc($result3);
            extract ($rowname);
         
         $sql4 = "INSERT INTO ItemsOrdered (orderID, sku, quantity)
                  VALUES ('$orderID', '$sku', '$quantity')";
         $result4 = mysqli_query($cxn, $sql4)
                    or die ("Couldn't execute insert into ItemsOrdered query.");
          header("Location: success4.php");
        }
      else {
          $message = "Staff member does not exist.<br />";
            include("createorder.inc");
      }
      
        break;
        default:
        include("createorder.inc");
   
   }
   
 ?>createorder.inc
Code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Adelaide Books</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div id="body">
<table id="main" cellspacing="0px">
<tr><td id="logo" colspan="3">
<img src="images/logo.gif" alt="Adelaide Books"/></td>
<td class="space"> </td>
<td class="right"> </td></tr>
<tr><td class="left"> </td>
<td class="space"> </td>
<td id="text">
<h1>Create New Order</h1>
   <form action="createorder.php" method="POST">
    <table width="250" border="0" align="center" cellpadding="2" cellspacing="2">
<?php
    if (isset($message)) {
        echo "<tr><td style='color:red' colspan='2' >$message <br /></td></tr>";
    }
?>
     <tr>
      <td width="75px" align="right">Staff ID:</td>
      <td><input type="text" name="staffID" size="25" maxsize="50"></td>
     </tr>
    <tr>
      <td width="75px" align="right">SKU:</td>
      <td><input type="text" name="sku" size="25" maxsize="50"></td>
     </tr>
    <tr>
      <td width="75px" align="right">Quantity:</td>
      <td><input type="text" name="quantity" size="10" maxsize="20"></td>
     </tr>
     <input type="hidden" name="do" value="neworder">
     <tr>
      <td colspan="2" align="center"><input type="submit" name="neworder" value="Submit"></td>
     </tr>
    </table>
   </form>
 <br/> <br/> <br/> <br/><a href="orders.php"><img src="images/back.gif" alt="Back" border="0" /></a></td>
<td class="space"> </td>
<td class="right"> </td></tr>
</table>
</div>
</body>
</html>
Hope someone can help!
Error in Configure System Landscape Directory phase
Hi
PHP Form to Variable.
Hi! I have written a HTML-form code in DreamWeaver CS3 (in a PHP doc) and I really need it to work soon :/I have a form:(<form name="form1" action=""
writing a screen scraper
Hello,I'm writing a screen scraper application and want to be able to get absolute addresses for images from relative links.So a link like this: Code: <img
Multi-image upload problems
Lets see if I can get some help on this one. Can anyone show me what I am doing wrong here. I'm just trying at this point to verify that the form inputs will work right. $max_img is set to 6. Here is
what are '%S%', '%E%'
for example when i see Code: [Select]printf("Hello %s\r\n", $name);what does %s means ?
a very simple php header question (sorry!)
Firstly...I do apologise if this annoys anyone....a header errorI'm do not know php & have tried removing all "white space" but I cant seem to stop the error displaying.Its a very
pointer 102 question
I read a book
in php, link returns to the line
When I add a link in a php page, the link word returns to the line (as a would do)Example:<a href="#">like</a></td> <td><a
Getting a variable to work in function params
I have this fuction which is inside a class:Code: public static function generateEmbedCode($callId, $width="425", $height="320", $swfobjectPath="SDK/js/swfobject.js",
Show message after entering data
Hello Colleagues I would like to display messages after entering the data example: " data were successfully " or " Error send data" in advance thanks.