jigsawsoul Posted August 9, 2009 Share Posted August 9, 2009 hey i still working on my uni. coursework, i just created the code for when a coustomer will buy a ticket from the website and the information is stored within the database below is my code. <?php session_start(); include '../library/opendb.php'; include '../library/functions/f_logs.php'; $eventid = $_GET['id']; $reqtickets = $_POST['reqtickets']; $cardtype = $_POST['cardtype']; $cardname = $_POST['cardname']; $cardnumber = $_POST['cardnumber']; $expirationdate = $_POST['expirationdate']; $billingaddress = $_POST['billingaddress']; $loginid = $_SESSION['login_id']; $query = "INSERT INTO sales (sale_id, login_id, event_id, reqtickets) VALUES (' ', '$loginid', '$eventid', '$reqtickets')"; if (mysql_query($query)) { // Success! } else { // Error! } $query = "INSERT INTO cards (card_id, amountcharged, cardtype, cardname, cardnumber, expirationdate, billingaddress) VALUES (' ', ' ', '$cardtype', '$cardname', '$cardnumber', '$expirationdate', '$billingaddress')"; if (mysql_query($query)) { // Success! $idcard = mysql_insert_id(); } else { // Error! } $query = "UPDATE gb_login SET card_id = '$idcard' WHERE login_id = $loginid"; if (mysql_query($query)) { // Success! } else { // Error! } $result = "SELECT * FROM events e LEFT JOIN artists ON e.artist_id=artists.artist_id LEFT JOIN venues ON e.venue_id=venues.venue_id LEFT JOIN sales ON e.event_id=sales.event_id LEFT JOIN gb_login ON sales.login_id=gb_login.login_id LEFT JOIN gb_customers ON gb_login.customer_id=gb_customers.customer_id WHERE e.event_id = {$_GET['id']}"; $result = mysql_query( $result ) or die ( mysql_error() ); $row = mysql_fetch_assoc ( $result ); $current_venue = $row['venue']; $current_artist = $row['artist']; $current_date = $row['date']; $current_price = $row['price']; $user_email = $row['email']; $user_firstname = $row['firstname']; $user_surname = $row['surname']; $subject = "Event Confirmation"; $web = "Gig Bookers"; $msg = "Gig Bookers - This is a confirmation email to say you have purchased $reqtickets Ticket(s) at price $current_price per ticket for $current_artist playing at $current_venue on $current_date. Thank You"; $body = "Sender: " . $user_firstname . " " . $user_surname . "\n\nEmail: " . $user_email . "\n\nWebsite: " . $web . "\n\nMessage:\n\n" . $msg; if (mail($user_email, $subject, $body)) { echo("confirmation email sent"); } else { echo("confirmation email couldn't send"); } $totalprice = ($current_price * $reqtickets); $query = "UPDATE cards SET amountcharged = '$totalprice' WHERE card_id = '$idcard'"; if (mysql_query($query)) { // Success! } else { // Error! } $query = "SELECT * FROM events WHERE event_id = $eventid"; $query = mysql_query( $query ) or die ( mysql_error() ); $row = mysql_fetch_assoc ( $query ); $alreadysold = $row['soldtickets']; $soldtickets = ($alreadysold + $reqtickets); $query = "UPDATE events SET soldtickets = '$soldtickets' WHERE event_id = '$eventid'"; if (mysql_query($query)) { // Success! } else { // Error } $_SESSION["message"] = '<div class="error mb">Your Tickets Will Be Sent To You By Post Within The Next Three Weeks, An Email H:as Been Sent To You To Confirm Your Booking, Thank You.</div>'; header ('Location: events.php'); ?> you guys think of a better way to do it, plus the header doesn't work at the bottem of the page i get: confirmation email sent Warning: Cannot modify header information - headers already sent by (output started at /home/hr728/public_html/webtwo/public/buy2.php:71) in /home/hr728/public_html/webtwo/public/buy2.php on line 105 but i think i know why now lol.. any ideas ? Quote Link to comment Share on other sites More sharing options...
kickstart Posted August 9, 2009 Share Posted August 9, 2009 Hi Header can only be used to redirect if NOTHING has been put to the screen (not even a blank line) before it is used. You script has put out a message about the confirmation email being output which will stop the redirect working. All the best Keith Quote Link to comment Share on other sites More sharing options...
nuttycoder Posted August 9, 2009 Share Posted August 9, 2009 if you need to use headers after output has started you can use output buffering it lets you call a header anywhere on a page. To use it put ob_start(); at the top of your file right after <?php Quote Link to comment Share on other sites More sharing options...
bundyxc Posted August 9, 2009 Share Posted August 9, 2009 Login first, then echo it all out. Example: //Instead of doing something like this echo 'I like the color '; if ($a == 1) { echo 'red.' } else { echo 'blue.'; } //Output: I like the color (red/blue). //Try something like this. $message = 'I like the color'; if ($a == 1) { $message .= 'red.' } else { $message .= 'blue.'; } if ($b == 2) { //Redirect user to another page, no output. } else { echo $message; //Output: I like the color (red/blue). } Quote Link to comment 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.