Jump to content

Insert Into not working


156418

Recommended Posts

I have the following code which is supposed to be taking values which have been posted, the values are posting ok as I can get them to Echo ok, but not put the values into the DB.

I'm connecting to the DB ok

[code]<?php

// make the variables easy to access in our queries
$_POST['cartId'] = $cartId;
$_POST['AdultQuantity'] = $AdultQuantity;
$_POST['Adult'] = $ATicketType;
$_POST['AdultPrice'] = $ATicketPrice;
$_POST['ChildQuantity'] = $ChildQuantity;
$_POST['Child'] = $CTicketType;
$_POST['ChildPrice'] = $CTicketPrice;
$_POST['PresentQuantity'] = $PresentQuantity;
$_POST['Present'] = $PTicketType;
$_POST['PresentPrice'] = $PTicketPrice;


//1) Add Adult Details to the CalcAdult Table
  $query = "INSERT INTO CalcAdult (
            cartId, AdultQuantity, Adult, AdultPrice)
            VALUES (
            '$cartId',
            '$AdultQuantity',
            '$ATicketType',
            '$ATicketPrice')";
  $insert = mysql_query($query)
    or (mysql_error());
?>
<?php
//2) Add Child Details to the CalcChild Table
  $query2 = "INSERT INTO CalcChild (
            cartId, ChildQuantity, Child, ChildPrice)
            VALUES (
            '$cartId',
            '$ChildQuantity',
            '$CTicketType',
            '$CTicketPrice')";
  $insert = mysql_query($query2)
    or (mysql_error());
?>
<?php
//3) Add Present Details to the CalcPresent Table
  $query3 = "INSERT INTO CalcPresent (
            cartId, PresentQuantity, Present, PresentPrice)
            VALUES (
            '$cartId',
            '$PresentQuantity',
            '$PTicketType',
            '$PTicketPrice')";
  $insert = mysql_query($query3)
    or (mysql_error());
?> [/code]

Thanks for any help
Link to comment
Share on other sites

I've tried both ways with no luck, either way results with an empty table  ???


[code]<?php

// make the variables easy to access in our queries
$cartId = $_POST['cartId'];
$AdultQuantity = $_POST['AdultQuantity'];
$ATicketType = $_POST['Adult'];
$ATicketPrice = $_POST['AdultPrice'];
$ChildQuantity = $_POST['ChildQuantity'];
$CTicketType = $_POST['Child'];
$CTicketPrice = $_POST['ChildPrice'];
$PresentQuantity = $_POST['PresentQuantity'];
$PTicketType = $_POST['Present'];
$PTicketPrice = $_POST['PresentPrice'];


//1) Add Adult Details to the CalcAdult Table
  $query = "INSERT INTO CalcAdult (
            cartId, AdultQuantity, Adult, AdultPrice)
            VALUES (
            '$cartId',
            '$AdultQuantity',
            '$ATicketType',
            '$ATicketPrice')";
  $insert = mysql_query($query)
    or (mysql_error());
?>
<?php
//2) Add Child Details to the CalcChild Table
  $query2 = "INSERT INTO CalcChild (
            cartId, ChildQuantity, Child, ChildPrice)
            VALUES (
            '$cartId',
            '$ChildQuantity',
            '$CTicketType',
            '$CTicketPrice')";
  $insert = mysql_query($query2)
    or (mysql_error());
?>
<?php
//3) Add Present Details to the CalcPresent Table
  $query3 = "INSERT INTO CalcPresent (
            cartId, PresentQuantity, Present, PresentPrice)
            VALUES (
            '$cartId',
            '$PresentQuantity',
            '$PTicketType',
            '$PTicketPrice')";
  $insert = mysql_query($query3)
    or (mysql_error());
?>
[/code]
Link to comment
Share on other sites

Time for a little bit of debug/echo assistance.

Change each query so you can see what's happening.  So change this (example):

[code]$insert = mysql_query($query)
    or (mysql_error());[/code]

to this (example):

[code]echo $query. "<br/>";
$insert = mysql_query($query) or die("Error ". mysql_error(). " with query ". $query);[/code]
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.