Jump to content


Photo

Insert Into not working


  • Please log in to reply
5 replies to this topic

#1 156418

156418
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 09 October 2006 - 10:06 AM

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

<?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());
?>

Thanks for any help

#2 baiju

baiju
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 09 October 2006 - 10:54 AM

you assigning data in opp direction

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

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

#3 156418

156418
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 09 October 2006 - 10:58 AM

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


<?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());
?> 


#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 09 October 2006 - 11:09 AM

Time for a little bit of debug/echo assistance.

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

$insert = mysql_query($query)
    or (mysql_error());

to this (example):

echo $query. "<br/>";
$insert = mysql_query($query) or die("Error ". mysql_error(). " with query ". $query);

Legend has it that reading the manual never killed anyone.
My site

#5 baiju

baiju
  • Members
  • PipPip
  • Member
  • 28 posts

Posted 09 October 2006 - 11:26 AM

then show your db coonection file

#6 156418

156418
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 09 October 2006 - 11:29 AM

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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users