Jump to content

PHP


westminster86

Recommended Posts

can someone help me out with the following code. ive filled out the form on the previous page. Created variables containing the form values but when i run this script its goin to the first else statement echo 'Could not store data, please try again.'; dunno why this happening.

 

is there something wrong with this line ....

  if($_SESSION['cart']&&$title&&$firstname&&$lastname&&$address&&$city&&$postcode&&$country)

 

$title = $_POST['title'];

  $firstname = $_POST['firstname'];

  $lastname = $_POST['lastname'];

  $address = $_POST['address'];

  $city = $_POST['city'];

  $postcode = $_POST['postcode'];

  $country = $_POST['country'];

 

  // if filled out

  if($_SESSION['cart']&&$title&&$firstname&&$lastname&&$address&&$city&&$postcode&&$country)

  {

    // able to insert into database

    if(insert_order($_POST)!=false)

    {

      // display cart, not allowing changes and without pictures

      display_cart($_SESSION['cart'], false, 0);

 

      display_shipping(calculate_shipping_cost());

     

      // get credit card details

      display_card_form($name);

 

      display_button('showCart.php', 'continue-shopping', 'Continue Shopping');

    }

    else

    {

      echo 'Could not store data, please try again.';

      display_button('checkout.php', 'back', 'Back');

    }

  }

  else

  {

    echo 'You did not fill in all the fields, please try again.<hr />';

    display_button('checkout.php', 'back', 'Back');

  }

 

do_html_footer();

 

Link to comment
Share on other sites

first step of de bugging. HAve you tried echoing the variables

$firstname = $_POST['firstname'];
  $lastname = $_POST['lastname'];
  $address = $_POST['address'];
  $city = $_POST['city'];
  $postcode = $_POST['postcode'];
  $country = $_POST['country'];

To ensure they contain information

Link to comment
Share on other sites

first step of de bugging. HAve you tried echoing the variables

$firstname = $_POST['firstname'];
  $lastname = $_POST['lastname'];
  $address = $_POST['address'];
  $city = $_POST['city'];
  $postcode = $_POST['postcode'];
  $country = $_POST['country'];

To ensure they contain information

 

 

yes i did that and they all have values...

Link to comment
Share on other sites

There is nothing wrong with that line, apart from that fact it's hideously unreadable. Not the OP fault either, it's reproduced from a book.

 

The reason for the error message is actually that insert_order($_POST) is evaluating to false, for whatever reason.

 

Edit: Just looking at the function, insert_order() (i have the book that this code has come from). It looks like you're going to have to modify that a fair bit to make it work with the additional fields you've added. I would imagine that one of the queries is failing somewhere along the line, causing the function to return false.

Link to comment
Share on other sites

  if($_SESSION['cart']&&$title&&$firstname&&$lastname&&$address&&$city&&$postcode&&$country)

 

This is how I handle forms in my PHP...

 

First I get the contents of all the form data and place into variables. I then check to see if the submit button has been pressed and if it has, go through and check each variable to see if the data is correct. If all the checks pass then I do whatever I need to with the data. If the submit button wasn't pressed or there was as error checking the data then my HTML form is displayed again but this time auto completed using the data I first gathered from it - error messages are displayed (if required) and the user can edit away and resubmit the form.

 

<?php
  $msg='Enter your name';
  $name=$_POST['username'];
  if ($_POST['subsend']) {
    if (!empty($name)) {
      //now do something with the data
    } else {
      $msg='error with the name';
    }
  }
?>
<html>
  <?php echo $msg; ?>
  <br />
  <form action="" method="post">
  Name: <input type="text" name="username" value="<?php echo stripslashes($name); ?>" />
  <input type="submit" name="subsend" value="Submit Name" />
  </form>
</html>

 

That's the sort of this I do - hope this helps in some way.

Link to comment
Share on other sites

There is nothing wrong with that line, apart from that fact it's hideously unreadable. Not the OP fault either, it's reproduced from a book.

 

The reason for the error message is actually that insert_order($_POST) is evaluating to false, for whatever reason.

 

Edit: Just looking at the function, insert_order() (i have the book that this code has come from). It looks like you're going to have to modify that a fair bit to make it work with the additional fields you've added. I would imagine that one of the queries is failing somewhere along the line, causing the function to return false.

 

ok thanks for that ill try fidling around with that insert_order line then

Link to comment
Share on other sites

There is nothing wrong with that line, apart from that fact it's hideously unreadable. Not the OP fault either, it's reproduced from a book.

 

The reason for the error message is actually that insert_order($_POST) is evaluating to false, for whatever reason.

 

Edit: Just looking at the function, insert_order() (i have the book that this code has come from). It looks like you're going to have to modify that a fair bit to make it work with the additional fields you've added. I would imagine that one of the queries is failing somewhere along the line, causing the function to return false.

 

ok thanks for that ill try fidling around with that insert_order line then

 

 

hey ginger seeing as it is returning false... how about if i just set it to true that way it would work...although not good programming practice

Link to comment
Share on other sites

You'll need to go through and change the various fields. You'll also need to modify the existing mysql database. Basically: you need to find everywhere that name is used, and split it into title, firstname and lastname; modify zip to postcode; and remove state.

 

i c u have the book to :) thanks for your help dude... im pretty crap at this stuff.

Link to comment
Share on other sites

You'll need to go through and change the various fields. You'll also need to modify the existing mysql database. Basically: you need to find everywhere that name is used, and split it into title, firstname and lastname; modify zip to postcode; and remove state.

 

i c u have the book to :) thanks for your help dude... im pretty crap at this stuff.

 

anyone know of any particular books that may be useful for starting out... i know the basics and stuff but was just looking at some sites and mines is just terrible compared.

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.