Jump to content

Recommended Posts

ok,

 

I have inserted all the customers info into all the necessary tables on the previous page. Also, on the previous page the customer enters in their credit card info..

 

Now on this page I am trying to update the credit card info into the orders table. I am having trouble getting the data to go in.

 

<?php
  include ('book_sc_fns.php');
  // The shopping cart needs sessions, so start one
  session_start();

  do_html_header('Checkout');

  $c_phone = $_POST['c_phone'];
  $c_email = $_POST['c_email'];
  $card_type = $_POST['card_type'];
  $card_number = $_POST['card_number'];
  $card_month = $_POST['card_month'];
  $card_year = $_POST['card_year'];
  $card_name = $_POST['card_name'];
  
  $name = $_SESSION['customer_name'];
  
$address = $_SESSION['customer_address'];


  if($_SESSION['cart']&&$c_phone&&$c_email&&$card_type&&$card_number&&
     $card_month&&$card_year&&$card_name )
  {
    //display cart, not allowing changes and without pictures 
    display_cart($_SESSION['cart'], false, 0);

    display_shipping(calculate_shipping_cost());  

    if(process_card($_POST))
    {
      //empty shopping cart
      session_destroy();
      echo 'Thankyou for shopping with us.  Your order has been placed.';
      display_button('index.php', 'continue-shopping', 'Continue Shopping');  
    }
    else
    {
    echo 'Could not process your card. ';
    echo 'Please contact the card issuer or try again.';
      display_button('purchase.php', 'back', 'Back');
    }
  }
  else
  {
    echo 'You did not fill in all the fields, please try again.<hr />';
    display_button('purchase.php', 'back', 'Back');
  } 

  do_html_footer();
?>

 

And here is the process_card() function.

 

<?php
function process_card($card_details)
{

  extract($card_details);
  
  
$conn = db_connect();

  // insert customer address
  $query = "UPDATE 'orders' SET 'c_phone' = '$c_phone', 'c_email' = '$c_email', 'card_type' = '$card_type', 'card_number' = '$card_number', 'card_month' = '$card_month', 'card_year' = '$card_year', 'card_name' = '$card_name' WHERE 'orders' . 'ship_name' = '$name'";
  
  

  $result = $conn->query($query);
  return true;
}

 

I still have a lot to learn, but I am starting to see things a little more clearly.

 

`Jake

 

Link to comment
https://forums.phpfreaks.com/topic/52922-solved-trouble-updating-data-into-table/
Share on other sites

Column name and table name must not have quate (')

Keep ` insted of '

 

$query = "UPDATE 'orders' SET `c_phone` = '$c_phone', `c_email`= '$c_email', `card_type` = '$card_type', `card_number` = '$card_number', `card_month` = '$card_month', `card_year` = '$card_year', `card_name` = '$card_name' WHERE `orders` . `ship_name` = '$name'";

 

 

I changed it to this:

 

<?php
function process_card($card_details)
{

  extract($card_details);
  
  
$conn = db_connect();

  // insert customer address
  $query = "UPDATE `orders` SET `c_phone` = '$c_phone', `c_email` = '$c_email', `card_type` = '$card_type', `card_number` = '$card_number', `card_month` = '$card_month', `card_year` = '$card_year', `card_name` = '$card_name' WHERE `orders` . `ship_name` = '$name'";
  
  
///   where  
          //  name = '$name' and address = '$address' 
          //  and city = '$city' and state = '$state' 
           // and zip = '$zip' and country = '$country'";

  $result = $conn->query($query);
  return true;
}

 

still no dice...

 

I don't know what the deal is..

orderid 	customerid 	amount 	date 	order_status 	ship_name 	ship_address 	ship_city 	ship_state 	ship_zip 	ship_country 	c_phone 	c_email 	card_type 	card_number 	card_month 	card_year 	card_name
Edit 	Delete 	8 	13 	5.27 	2007-05-25 	PARTIAL 	test 	test 	test 	test 	test 	test 	0 	0 	0 	0 	0 	0 	0

 

I am trying to tell it what row I want it to update to.  ship_name is the name of a column where the customers name is stored,    I was trying to get it to store the data where the customers name that is stored in the session matches the name in that column.

Does this part of my code look ok?

if($_SESSION['cart']&&$c_phone&&$c_email&&$card_type&&$card_number&&
     $card_month&&$card_year&&$card_name )
  {
    //display cart, not allowing changes and without pictures 
    display_cart($_SESSION['cart'], false, 0);

    display_shipping(calculate_shipping_cost());  

    if(process_card($_POST))
    {
      //empty shopping cart
      session_destroy();
      echo 'Thankyou for shopping with us.  Your order has been placed.';
      display_button('index.php', 'continue-shopping', 'Continue Shopping');  
    }

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.