Jump to content

Archived

This topic is now archived and is closed to further replies.

156418

Insert Into not working

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

Share this post


Link to post
Share on other sites
you assigning data in opp direction

$_POST['cartId'] = $cartId;
$_POST['AdultQuantity'] = $AdultQuantity;

it should be
$cartId = $_POST['cartId'] ;
$AdultQuantity=$_POST['AdultQuantity']  ;

Share this post


Link to post
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]

Share this post


Link to post
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]

Share this post


Link to post
Share on other sites
The Echo assisted in this one.

It was grumbling about some of the names of the values being passed, I've set them all exact now (in the form compared with the DB) and its worked ok

Thanks for the help

Share this post


Link to post
Share on other sites

×

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.