Jump to content

Inserting into database


thomashw

Recommended Posts

If something isn't being inserted into the database when it should be, and I'm not getting any errors, what's the best way to try to solve the problem?

 

It inserts into one table, but after the first table has been updated, it doesn't insert into the rest of the tables.

 

Here's my script (sorry it's so long). The insert into customer_info works, but inserting into ordermain or orderdet don't work. It also doesn't delete form order_temp.

 

<?
session_start();
include("dbinfo.php");

$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$add1 = $_POST['add1'];
$add2 = $_POST['add2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$country = $_POST['country'];
$phone = $_POST['phone'];
$fax = $_POST['fax'];
$email = $_POST['email'];
$shipfirst = $_POST['shipfirst'];
$shiplast = $_POST['shiplast'];
$shipadd1 = $_POST['shipadd1'];
$shipadd2 = $_POST['shipadd2'];
$shipcity = $_POST['shipcity'];
$shipstate = $_POST['shipstate'];
$shipzip = $_POST['shipzip'];
$shipcountry = $_POST['shipcountry'];
$shipphone = $_POST['shipphone'];
$shipemail = $_POST['shipemail'];
$total = $_POST['total'];
$sessid = session_id();
$today = date("Y-m-d-");

$query = "SELECT * FROM customer_info 
WHERE (customer_firstname = '$firstname' 
AND customer_lastname = '$lastname' 
AND customer_streetaddress1 = '$add1' 
AND customer_streetaddress2 = '$add2' 
AND customer_city = '$city')";
$results = mysql_query($query) or (mysql_error());
$rows = mysql_num_rows($results);

if ($rows < 1) {
$query2 = "INSERT INTO customer_info (
customer_firstname, 
customer_lastname, 
customer_streetaddress1, 
customer_streetaddress2, 
customer_city, 
customer_stateprov, 
customer_zippcode, 
customer_country, 
customer_phone, 
customer_fax, 
customer_email, 
customer_dateadded) 
VALUES (
'$firstname', 
'$lastname', 
'$add1', 
'$add2', 
'$city', 
'$state', 
'$zip', 
'$country', 
'$phone', 
'$fax', 
'$email', 
'$today')";
$insert = mysql_query($query2) or (mysql_error());
$custid = mysql_insert_id();
}

if($custid) {
$customer_id = $custid;
}

$query3 = "INSERT INTO ordermain (
ordermain_orderdate, 
ordermain_customer_id, 
ordermain_subtotal, 
ordermain_shipping, 
ordermain_shipfirst, 
ordermain_shiplast, 
ordermain_shipadd1, 
ordermain_shipadd2, 
ordermain_shipcity, 
ordermain_shipstate, 
ordermain_shipzip, 
ordermain_shipcountry, 
ordermain_shipphone, 
ordermain_shipemail) 
VALUES (
'$today',
'$customer_id', 
'$total', 
'$shipping', 
'$shipfirst',
'$shiplast',
'$shipadd1', 
'$shipadd2', 
'$shipcity', 
'$shipstate', 
'$shipzip', 
'$shipcountry', 
'$shipphone', 
'$shipemail')";
$insert2 = mysql_query($query3) or (mysql_error());
$orderid = mysql_insert_id();

$query4 = "SELECT * FROM ordertemp WHERE ordertemp_sess='$sessid'";
$results = mysql_query($query4) or (mysql_error());

while ($row = mysql_fetch_array($results)) {
extract($row);
$query5 = "INSERT INTO orderdet ( 
orderdet_ordernum, 
orderdet_qty, 
orderdet_product_id) VALUES ( 
'$orderid', 
'$ordertemp_quan', 
'$ordertemp_product_id')";
$insert4 = mysql_query($query5) or (mysql_error());
}

$query6 = "DELETE FROM ordertemp WHERE ordertemp_sess='$sessid'";
$delete = mysql_query($query6);

 

Any ideas? :-\

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.