westminster86 Posted January 4, 2008 Share Posted January 4, 2008 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(); Quote Link to comment https://forums.phpfreaks.com/topic/84476-php/ Share on other sites More sharing options...
adam291086 Posted January 4, 2008 Share Posted January 4, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/84476-php/#findComment-430385 Share on other sites More sharing options...
westminster86 Posted January 4, 2008 Author Share Posted January 4, 2008 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... Quote Link to comment https://forums.phpfreaks.com/topic/84476-php/#findComment-430387 Share on other sites More sharing options...
adam291086 Posted January 4, 2008 Share Posted January 4, 2008 i think there maybe a problem with that line. Have you tried just putting if (isset($_SESSION['cart']) and seeing if it work. If you are wanting to check the varible have information do it the simple way and us the empty function. Quote Link to comment https://forums.phpfreaks.com/topic/84476-php/#findComment-430390 Share on other sites More sharing options...
westminster86 Posted January 4, 2008 Author Share Posted January 4, 2008 i think there maybe a problem with that line. Have you tried just putting if (isset($_SESSION['cart']) and seeing if it work. If you are wanting to check the varible have information do it the simple way and us the empty function. still nothing Quote Link to comment https://forums.phpfreaks.com/topic/84476-php/#findComment-430399 Share on other sites More sharing options...
adam291086 Posted January 4, 2008 Share Posted January 4, 2008 you have got session_start() at the top of the page. Also echo the session out to see if its set Quote Link to comment https://forums.phpfreaks.com/topic/84476-php/#findComment-430401 Share on other sites More sharing options...
GingerRobot Posted January 4, 2008 Share Posted January 4, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/84476-php/#findComment-430405 Share on other sites More sharing options...
Yesideez Posted January 4, 2008 Share Posted January 4, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/84476-php/#findComment-430412 Share on other sites More sharing options...
westminster86 Posted January 4, 2008 Author Share Posted January 4, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/84476-php/#findComment-430448 Share on other sites More sharing options...
GingerRobot Posted January 4, 2008 Share Posted January 4, 2008 Its not the line, its the entire insert_order() function. Quote Link to comment https://forums.phpfreaks.com/topic/84476-php/#findComment-430449 Share on other sites More sharing options...
westminster86 Posted January 4, 2008 Author Share Posted January 4, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/84476-php/#findComment-430450 Share on other sites More sharing options...
GingerRobot Posted January 4, 2008 Share Posted January 4, 2008 Yeah, but the data would then not get inserted into the database. Quote Link to comment https://forums.phpfreaks.com/topic/84476-php/#findComment-430457 Share on other sites More sharing options...
westminster86 Posted January 4, 2008 Author Share Posted January 4, 2008 Yeah, but the data would then not get inserted into the database. i didnt think about that... thats not guna do me ne good then :-\ u got ne suggestions to wht i shld do... hw cn i change the function? Quote Link to comment https://forums.phpfreaks.com/topic/84476-php/#findComment-430498 Share on other sites More sharing options...
GingerRobot Posted January 4, 2008 Share Posted January 4, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/84476-php/#findComment-430516 Share on other sites More sharing options...
westminster86 Posted January 4, 2008 Author Share Posted January 4, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/84476-php/#findComment-430533 Share on other sites More sharing options...
westminster86 Posted January 4, 2008 Author Share Posted January 4, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/84476-php/#findComment-430549 Share on other sites More sharing options...
GingerRobot Posted January 4, 2008 Share Posted January 4, 2008 See here for a discussion on PHP and web design books. Quote Link to comment https://forums.phpfreaks.com/topic/84476-php/#findComment-430554 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.