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
https://forums.phpfreaks.com/topic/23410-insert-into-not-working/
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]
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]

Archived

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

×
×
  • 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.