0

hello Dear friend
i can't explain cause i dont' know why, i'm using the code below to insert data into a myql table but i work fine ust today i get a error colum subtotal can't be null... i' have try too much thing but still same i delete the colum subtotal in database and in php (insert into table...)
and same errot for next colum can somebody explaain why i get 'Column 'total' cannot be null' in my page when i submit to insert the data??? below is the code:

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "valide")) {
  $insertSQL = sprintf("INSERT INTO commande (sku, client, `date`, subtotal, total) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['sku'], "text"),
                       GetSQLValueString($_POST['client'], "text"),
                       GetSQLValueString($_POST['date'], "date"),
                       GetSQLValueString($_POST['subtotal2'], "double"),
                       GetSQLValueString($_POST['total'], "int"));

  mysql_select_db($database_marketbase, $marketbase);
  $Result1 = mysql_query($insertSQL, $marketbase) or die(mysql_error());

  $insertGoTo = "../myspace/order-line.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
    echo $insertGoTo;
  }
  header(sprintf("Location: %".$insertGoTo));
}
<form name="valide" method="POST" action="<?php echo $editFormAction; ?>">
          <label for="Sub total"></label>
          <label for="shipping">Sub total</label><input name="subtotal2" type="text" disabled value="<?php echo number_format($row_total['sub_total'], 2, '.', ''); ?>" readonly disabledid="subtotal2">
          <label for="shipping">Shipping</label>
           <input name="shipping" type="text" id="shipping" value="<?php echo number_format($row_total['shipping'], 2, '.', ''); ?>" readonly>
          <label for="total"></label>
          <label for="shipping">Total</label><input name="total" type="text" disabled id="total" value="<?php echo number_format ($row_total['total'], 2, '.', ''); ?>" readonly>
          <input name="date" type="hidden" id="date" value="<?php echo $row_total['date']; ?>">
          <input name="sku" type="hidden" id="sku" value="<?php echo $row_total['sku']; ?>">
          <input type="hidden" name="client" id="client" value="<?php echo $_SESSION['MM_Username'] ?>">
<input type="submit" name="button" id="button" value="Place an order">
<input type="hidden" name="MM_insert" value="valide">
        </form>
2
Contributors
3
Replies
21
Views
3 Years
Discussion Span
Last Post by chrisschristou
1

Is the total field declared as NOT NULL in your table? If it has to have a value you have to make sure the value exists in the query.

You can also check the query if you insert this temporary debug code on line 8:

die($insertSQL);

This will display the constructed query and stop the script. You can examine the query or copy it to phpmyadmin and test it there.

Edited by broj1

0

hello thank to answer me i use the code you gave me i use it on line 8

die($insertSQL);

and i got this out of page: INSERT INTO commande (sku, client, date, subtotal, total) VALUES ('ZNPNX920', 'username', '2013-09-21 16:11:10', NULL, NULL) still i can't undestund why subtotal and total are NULL??

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "valide")) {
  $insertSQL = sprintf("INSERT INTO commande (sku, client, `date`, subtotal, total) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['sku'], "text"),
                       GetSQLValueString($_POST['client'], "text"),
                       GetSQLValueString($_POST['date'], "date"),
                       GetSQLValueString($_POST['subtotal2'], "double"),
                       GetSQLValueString($_POST['total'], "int"));
die($insertSQL);
  mysql_select_db($database_marketbase, $marketbase);
  $Result1 = mysql_query($insertSQL, $marketbase) or die(mysql_error());

all get are from here this form :

<form name="valide" method="POST" action="<?php echo $editFormAction; ?>">
          <label for="Sub total"></label>
          <label for="shipping">Sub total</label><input name="subtotal2" type="text" disabled value="<?php echo number_format($row_total['sub_total'], 2, '.', ''); ?>" readonly disabledid="subtotal2">
          <label for="shipping">Shipping</label>
           <input name="shipping" type="text" id="shipping" value="<?php echo number_format($row_total['shipping'], 2, '.', ''); ?>" readonly>
          <label for="total"></label>
          <label for="shipping">Total</label><input name="total" type="text" disabled id="total" value="<?php echo number_format ($row_total['total'], 2, '.', ''); ?>" readonly>
          <input name="date" type="hidden" id="date" value="<?php echo $row_total['date']; ?>">
          <input name="sku" type="hidden" id="sku" value="<?php echo $row_total['sku']; ?>">
          <input type="hidden" name="client" id="client" value="<?php echo $_SESSION['MM_Username'] ?>">
<input type="submit" name="button" id="button" value="Place an order">
<input type="hidden" name="MM_insert" value="valide">
        </form>
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.