Paul_Withers Posted October 5, 2014 Share Posted October 5, 2014 Hi, I got this form, but I dont want the form to be displayed if the user has run out of credits. The page worked until I added the credit check and now I get this error Parse error: syntax error, unexpected end of file in /Applications/XAMPP/xamppfiles/htdocs/other_items.php on line 269 I know this is because some } are missing, but whenever I move them about, it either doesnt work, or says there is no { to match the } with. Im really confused now and got another 2 pages to do this to, so really need to sort this one out. Here is what I got <?php include 'init.php'; include 'includes/overall/header.php'; include 'includes/logo.php'; if (!isset($_SESSION['loggedin'])) { die("You must be logged in to sell a item"); //this causes to script to stop executing and lets the user know there is a problem /* Note: instead of the die() function, you could use the echo() function and provide an HTML link back to the login page, or use the header() function to just redirect users to the login page without any message. It is up to you to decide what your application should behave. */ } //else { //logged in elseif (isset($_SESSION['loggedin']) ){ //logged in $username = $_SESSION['loggedinuser']; $results = $con->query("SELECT * FROM user WHERE username = '$username';"); while($row = $results->fetch_array()) { $email = $row['email']; $town = $row['town']; $county = $row['county']; } } // THIS IS NEW // CHECK WHETHER USER HAS CREDITS REMAINING $query = "SELECT SUM(amount) FROM transaction WHERE username = $username"; $result = mysqli_query($con, $query); if($result) { $row = mysqli_fetch_row($result); $amount = $row['amount']; if ( ($amount) <= 0) { //not enough credits - show message and redirect echo "You either have no remaining credits or not enough to complete this transaction. You will be redirected to purchase more."; header( "Refresh:5; url=purchase.php", true, 303); exit(); } else { // UP TO HERE ?> <script type="text/javascript" src="jquery.js"></script> <form action="otherItemsCheck.php" id="sellForm" method="POST"> <input type="hidden" name="username" value="<?php echo $username ?>"></li> <input type="hidden" name="email" value="<?php echo $email ?>"></li> <input type="hidden" name="town" value="<?php echo $town ?>"></li> <input type="hidden" name="county" value="<?php echo $county ?>"></li> <h2>Sell your item</h2> <p><strong>A basic listing will cost 1 credit - extras will be added to the total cost of your listing</strong></p> <ul> <li>Category*:</br> <select name="category"> <option value="none">--choose--</option> <option value="air_pumps">Air Pumps</option> <option value="air_stones">Air Stones</option> <option value="aquariums">Aquariums</option> <option value="cleaning">Cleaning & Maintenance</option> <option value="equipment">CO2 Equipment</option> <option value="coral">Coral & Live Rock</option> <option value="decorations">Decorations</option> <option value="feeders">Feeders</option> <option value="filter_media">Filter Media & Accessories</option> <option value="food">Food</option> <option value="gravel">Gravel & Substrate</option> <option value="health_care">Health Care</option> <option value="heaters">Heaters & Chillers </option> <option value="lighting">Lighting & Hoods</option> <option value="meters">Meters & Controllers</option> <option value="deionization">Reverse Osmosis & Deionization </option> <option value="tubing">Tubing & Valves</option> <option value="uv">UV Steriliser Water Pumps</option> <option value="water_tests">Water Tests & Treatment</option> <option value="other">Other Fish & Aquarium</option> </select> </li> <li>Listing Title*:</br> <input type="text" name="listing_title"> <li><strong>Would you like your listing displayed in Bold?: <input type="checkbox" name="bold" value="1"/> 1 Credit</strong> </li> <li>Condition*:</br> <select name="item_condition"> <option>--choose--</option> <option value="New (Packaged)">New (Packaged)</option> <option value="New (None or damaged packaging">New (None or damaged packaging</option> <option value="Used - Working">Used - Working</option> <option value="Used - Not Working">Used - Not Working</option> </select> </li> <li>Brand*:</br> <select name="brand"> <option>Choose...</option> <option value="AI (Aqua Illumination)">AI (Aqua Illumination)</option> <option value="Algarde">Algarde</option> <option value="API">API</option> <option value="AquaEl">AquaEl</option> <option value="AquaGro">AquaGro</option> <option value="Aquamedic">Aquamedic</option> <option value="Aquarian">Aquarian</option> <option value="Aquarium Systems">Aquarium Systems</option> <option value="Aquatlantis">Aquatlantis</option> <option value="Arcadia">Arcadia</option> <option value="Azoo">Azoo</option> <option value="BiOrb/Reef One">BiOrb/Reef One</option> <option value="Blagdon">Blagdon</option> <option value="Boyu">Boyu</option> <option value="Classica">Classica</option> <option value="Cloverleaf">Cloverleaf</option> <option value="Deltec/D-D">Deltec/D-D</option> <option value="Dennerle">Dennerle</option> <option value="Eheim">Eheim</option> <option value="ESHa">ESHa</option> <option value="Hagen/Fluval">Hagen/Fluval</option> <option value="Hikari">Hikari</option> <option value="Hobby">Hobby</option> <option value="Hugo Kamishi">Hugo Kamishi</option> <option value="Interpet">Interpet </option> <option value="JMC">JMC</option> <option value="Juwel">Juwel</option> <option value="King British">King British</option> <option value="New Era">New Era</option> <option value="Nishikoi">Nishikoi</option> <option value="NT Labs">NT Labs</option> <option value="Oase">Oase</option> <option value="Ocean Nutrition">Ocean Nutrition</option> <option value="Penn Plax">Penn Plax</option> <option value="Pontec">Pontec</option> <option value="Red Sea">Red Sea</option> <option value="Rena">Rena</option> <option value="Salifert">Salifert</option> <option value="Seachem">Seachem</option> <option value="Seneye">Seneye</option> <option value="SuperFish">SuperFish</option> <option value="Tanktests">Tanktests</option> <option value="Tetra">Tetra</option> <option value="TMC">TMC</option> <option value="Tunze">Tunze</option> <option value="Two Little Fishies">Two Little Fishies</option> <option value="Waterlife">Waterlife</option> <option value="Wave Point">Wave Point</option> <option value="other">Other</option> </select> </li> <li>Model*:</br> <input type="text" name="model"> </li> <li>Colour*:</br> <select name="colour"> <option value="">--choose one--</option> <option value="White">White</option> <option value="Grey">Grey</option> <option value="Black">Black</option> <option value="Blue">Blue</option> <option value="Green">Green</option> <option value="Orange">Orange</option> <option value="Red">Red</option> <option value="Multicoloured">Multicoloured</option> <option value="Other">Other</option> </select> </li> <li>Quantity*:</br> <select name="quantity"> <option value="">--choose one--</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select><strong> 1 Credit entitles you to sell up to 10 of the same item. </strong> </li> <li>Price*:<br> <input type="text" name="price"> In UK Pound Sterling </li> <li>Description*:</br> <textarea name="comments"></textarea> </li> <li>Postage Type*:</br> <select name="postage_type"> <option>Choose...</option> <option disabled>Economy services</option> <option value="UK_CollectPlusTracked">Collect+ Economy Tracked (3 to 5 working days)</option> <option value="UK_HermesTracked">Hermes Tracked (3 to 5 working days)</option> <option value="UK_RoyalMailSecondClassStandard">Royal Mail 2nd Class (2 to 3 working days)</option> <option value="UK_RoyalMailSecondClassRecorded">Royal Mail 2nd Class Signed For (2 to 3 working days)</option> <option value="UK_RoyalMailTracked">Royal Mail Tracked 48 (2 to 3 working days)</option> <option value="UK_RoyalMail48">Royal Mail 48 (2 to 3 working days)</option> <option value="UK_OtherCourier3Days">Other Courier 3 days (3 working days)</option> <option value="UK_OtherCourier5Days">Other Courier 5 days (5 working days)</option> <option value="UK_OtherCourier">Other Courier (3 to 5 working days)</option> <option value="UK_SellersStandardRate">Other Courier 3-5 days (3 to 5 working days)</option> <option disabled>Standard services</option> <option value="UK_RoyalMailFirstClassStandard">Royal Mail 1st Class (1 working day)</option> <option value="UK_RoyalMailFirstClassRecorded">Royal Mail 1st Class Signed For (1 working day)</option> <option value="UK_RoyalMailNextDay">Royal Mail Tracked 24 (1 working day)</option> <option value="UK_RoyalMail24">Royal Mail 24 (1 working day)</option> <option value="UK_CollectPlusStandard">Collect+ Standard (2 working days)</option> <option value="UK_Parcelforce48">Parcelforce 48 (1 to 2 working days)</option> <option value="UK_OtherCourier48">Other 48 Hour Courier (1 to 2 working days)</option> <option disabled>Express services</option> <option value="UK_RoyalMailSpecialDeliveryNextDay">Royal Mail Special Delivery (TM) 1:00 pm (1 working day)</option> <option value="UK_RoyalMailSpecialDelivery9am">Royal Mail Special Delivery (TM) 9:00 am (1 working day)</option> <option value="UK_Parcelforce24">Parcelforce 24 (1 working day)</option> <option value="UK_OtherCourier24">Other 24 Hour Courier (1 working day)</option> <option disabled>Services from outside UK</option> <option value="UK_EconomyShippingFromOutside">Economy Delivery from outside UK (10 to 22 working days)</option> <option value="StandardDeliveryfromOutsideUKwithRoyalMail">Standard Delivery from outside UK with Royal Mail (7 to 13 working days)</option> <option value="UK_StandardShippingFromOutside">Standard Delivery from outside UK (4 to 10 working days)</option> <option value="UK_ExpeditedShippingFromOutside">Express Delivery from outside UK (1 to 3 working days)</option> <option value="UK_FedExIntlEconomy">FedEx International Economy (3 to 4 working days)</option> <option value="UK_TntIntlExp">TNT International Express (2 to 3 working days)</option> <option value="UK_TrackedDeliveryFromAbroad">Tracked delivery from outside UK (2 to 5 working days)</option> <option disabled>Collection</option> <option value="UK_CollectInPerson">Collection in Person </option> </select> </li> <li>Postage Cost*:</br> <input type="text" name="postage_cost"> </li> </ul> <ul> <li>Upload Photo:</br> <input id="text" type="text" name="upload_photo"> </li> <li><input type="checkbox" name="rotate" value="10"/><strong>For 10 credits, you can have your listing displayed on our homepage on a rotation basis. </strong> </li> <li> <input type="submit" value="List Item"></li> </ul> </form> <script type="text/javascript" src="saleSpecies.js"></script> <?php } include 'includes/overall/footer.php'; ?> eg, it says this } here: <?php } include 'includes/overall/footer.php'; ?> Is unmatched. I know whats wrong, just not how to fix it Any help is always much appreciated. aquaman Quote Link to comment Share on other sites More sharing options...
ginerjm Posted October 5, 2014 Share Posted October 5, 2014 What does "it says this ) here" mean? The message is telling you the file and line number. Show us that. More importantly the line number is a good hint of where to look. If it is the end of the named file, then you are definitely missing a curly brace. Walk thru your code looking to see that they are all paired up. If you are using a good ide that highlights your code it s/b easy to locate the unmatched brace; otherwise it's a pia but a necessary part of debugging. Quote Link to comment Share on other sites More sharing options...
Paul_Withers Posted October 5, 2014 Author Share Posted October 5, 2014 Nope it is a } not a ) and "it says this } here" <?php } include 'includes/overall/footer.php'; ?> as in the } after <?php at the foot of the file. Error is on line 269 as stated in my first post Parse error: syntax error, unexpected end of file in /Applications/XAMPP/xamppfiles/htdocs/other_items.php on line 269 I know there are closing } missing but I cannot work out where to put the, without my text editor saying the } is unmatched. I dont know how to put this any clearer. Thanks aquaman Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted October 5, 2014 Share Posted October 5, 2014 You need to go through your code and make sure each statement has matching opening and closing braces. If you had formatted your code it'll be alot easier to identify where the closing brace should go. Ideally every time you open a brace you should indent the code by one when you type a closing brace you remove a tab example if( conditon ) { statemet1; statement2; while( something ) { doThis; andThat; } } Notice the opening and closing braces all line up, each statement is neatly indented. This is how you should format your code. Also if you are going to use large chunks of HTML in your code consider moving it to another file and use include/require when you need it. You should try to keep your HTML and PHP code separate as much as possible. Quote Link to comment Share on other sites More sharing options...
Barand Posted October 5, 2014 Share Posted October 5, 2014 You need to go through your code and make sure each statement has matching opening and closing braces. I think the purpose of his post was for us to do that for him 1 Quote Link to comment Share on other sites More sharing options...
jcbones Posted October 5, 2014 Share Posted October 5, 2014 You are missing a closing brace { for this statement. if($result) { Quote Link to comment Share on other sites More sharing options...
Barand Posted October 5, 2014 Share Posted October 5, 2014 BTW, } else { <--------------- this currently matches with // UP TO HERE ?> <?php } <---------------- this one that you said was unmatched include 'includes/overall/footer.php'; ?> Quote Link to comment Share on other sites More sharing options...
Solution Paul_Withers Posted October 5, 2014 Author Solution Share Posted October 5, 2014 Its ok I done it thank you Barand, and just for your information, I dont expect anybody to go through my code working out if statements, I was just staring at it and getting nowhere and my editor was not helping. So I thought I would post a question in a forum, I mean isnt that what they are for? Anyway, if anyone is interested, the code is <?php include 'init.php'; include 'includes/overall/header.php'; include 'includes/logo.php'; if (!isset($_SESSION['loggedin'])) { die("You must be logged in to sell a item"); //this causes to script to stop executing and lets the user know there is a problem /* Note: instead of the die() function, you could use the echo() function and provide an HTML link back to the login page, or use the header() function to just redirect users to the login page without any message. It is up to you to decide what your application should behave. */ } //else { //logged in elseif (isset($_SESSION['loggedin']) ){ //logged in $username = $_SESSION['loggedinuser']; $results = $con->query("SELECT * FROM user WHERE username = '$username';"); while($row = $results->fetch_array()) { $email = $row['email']; $town = $row['town']; $county = $row['county']; $sql1="SELECT sum(amount) as amount FROM transaction WHERE posted_by = '$username'"; $result1 = mysqli_query($con, $sql1); while ($row = mysqli_fetch_assoc($result1)) { $credits = $row['amount']; if ($credits <= 0) { //not enough credits - show message and redirect echo "You have no remaining credits. You will be redirected to purchase more."; header( "Refresh:5; url=purchase.php", true, 303); exit(); } else { ?> <script type="text/javascript" src="jquery.js"></script> <form action="otherItemsCheck.php" id="sellForm" method="POST"> <input type="hidden" name="username" value="<?php echo $username ?>"></li> <input type="hidden" name="email" value="<?php echo $email ?>"></li> <input type="hidden" name="town" value="<?php echo $town ?>"></li> <input type="hidden" name="county" value="<?php echo $county ?>"></li> <h2>Sell your item</h2> <p><strong>A basic listing will cost 1 credit - extras will be added to the total cost of your listing</strong></p> <ul> <li>Category*:</br> <select name="category"> <option value="none">--choose--</option> <option value="air_pumps">Air Pumps</option> <option value="air_stones">Air Stones</option> <option value="aquariums">Aquariums</option> <option value="cleaning">Cleaning & Maintenance</option> <option value="equipment">CO2 Equipment</option> <option value="coral">Coral & Live Rock</option> <option value="decorations">Decorations</option> <option value="feeders">Feeders</option> <option value="filter_media">Filter Media & Accessories</option> <option value="food">Food</option> <option value="gravel">Gravel & Substrate</option> <option value="health_care">Health Care</option> <option value="heaters">Heaters & Chillers </option> <option value="lighting">Lighting & Hoods</option> <option value="meters">Meters & Controllers</option> <option value="deionization">Reverse Osmosis & Deionization </option> <option value="tubing">Tubing & Valves</option> <option value="uv">UV Steriliser Water Pumps</option> <option value="water_tests">Water Tests & Treatment</option> <option value="other">Other Fish & Aquarium</option> </select> </li> <li>Listing Title*:</br> <input type="text" name="listing_title"> <li><strong>Would you like your listing displayed in Bold?: <input type="checkbox" name="bold" value="1"/> 1 Credit</strong> </li> <li>Condition*:</br> <select name="item_condition"> <option>--choose--</option> <option value="New (Packaged)">New (Packaged)</option> <option value="New (None or damaged packaging">New (None or damaged packaging</option> <option value="Used - Working">Used - Working</option> <option value="Used - Not Working">Used - Not Working</option> </select> </li> <li>Brand*:</br> <select name="brand"> <option>Choose...</option> <option value="AI (Aqua Illumination)">AI (Aqua Illumination)</option> <option value="Algarde">Algarde</option> <option value="API">API</option> <option value="AquaEl">AquaEl</option> <option value="AquaGro">AquaGro</option> <option value="Aquamedic">Aquamedic</option> <option value="Aquarian">Aquarian</option> <option value="Aquarium Systems">Aquarium Systems</option> <option value="Aquatlantis">Aquatlantis</option> <option value="Arcadia">Arcadia</option> <option value="Azoo">Azoo</option> <option value="BiOrb/Reef One">BiOrb/Reef One</option> <option value="Blagdon">Blagdon</option> <option value="Boyu">Boyu</option> <option value="Classica">Classica</option> <option value="Cloverleaf">Cloverleaf</option> <option value="Deltec/D-D">Deltec/D-D</option> <option value="Dennerle">Dennerle</option> <option value="Eheim">Eheim</option> <option value="ESHa">ESHa</option> <option value="Hagen/Fluval">Hagen/Fluval</option> <option value="Hikari">Hikari</option> <option value="Hobby">Hobby</option> <option value="Hugo Kamishi">Hugo Kamishi</option> <option value="Interpet">Interpet </option> <option value="JMC">JMC</option> <option value="Juwel">Juwel</option> <option value="King British">King British</option> <option value="New Era">New Era</option> <option value="Nishikoi">Nishikoi</option> <option value="NT Labs">NT Labs</option> <option value="Oase">Oase</option> <option value="Ocean Nutrition">Ocean Nutrition</option> <option value="Penn Plax">Penn Plax</option> <option value="Pontec">Pontec</option> <option value="Red Sea">Red Sea</option> <option value="Rena">Rena</option> <option value="Salifert">Salifert</option> <option value="Seachem">Seachem</option> <option value="Seneye">Seneye</option> <option value="SuperFish">SuperFish</option> <option value="Tanktests">Tanktests</option> <option value="Tetra">Tetra</option> <option value="TMC">TMC</option> <option value="Tunze">Tunze</option> <option value="Two Little Fishies">Two Little Fishies</option> <option value="Waterlife">Waterlife</option> <option value="Wave Point">Wave Point</option> <option value="other">Other</option> </select> </li> <li>Model*:</br> <input type="text" name="model"> </li> <li>Colour*:</br> <select name="colour"> <option value="">--choose one--</option> <option value="White">White</option> <option value="Grey">Grey</option> <option value="Black">Black</option> <option value="Blue">Blue</option> <option value="Green">Green</option> <option value="Orange">Orange</option> <option value="Red">Red</option> <option value="Multicoloured">Multicoloured</option> <option value="Other">Other</option> </select> </li> <li>Quantity*:</br> <select name="quantity"> <option value="">--choose one--</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select><strong> 1 Credit entitles you to sell up to 10 of the same item. </strong> </li> <li>Price*:<br> <input type="text" name="price"> In UK Pound Sterling </li> <li>Description*:</br> <textarea name="comments"></textarea> </li> <li>Postage Type*:</br> <select name="postage_type"> <option>Choose...</option> <option disabled>Economy services</option> <option value="UK_CollectPlusTracked">Collect+ Economy Tracked (3 to 5 working days)</option> <option value="UK_HermesTracked">Hermes Tracked (3 to 5 working days)</option> <option value="UK_RoyalMailSecondClassStandard">Royal Mail 2nd Class (2 to 3 working days)</option> <option value="UK_RoyalMailSecondClassRecorded">Royal Mail 2nd Class Signed For (2 to 3 working days)</option> <option value="UK_RoyalMailTracked">Royal Mail Tracked 48 (2 to 3 working days)</option> <option value="UK_RoyalMail48">Royal Mail 48 (2 to 3 working days)</option> <option value="UK_OtherCourier3Days">Other Courier 3 days (3 working days)</option> <option value="UK_OtherCourier5Days">Other Courier 5 days (5 working days)</option> <option value="UK_OtherCourier">Other Courier (3 to 5 working days)</option> <option value="UK_SellersStandardRate">Other Courier 3-5 days (3 to 5 working days)</option> <option disabled>Standard services</option> <option value="UK_RoyalMailFirstClassStandard">Royal Mail 1st Class (1 working day)</option> <option value="UK_RoyalMailFirstClassRecorded">Royal Mail 1st Class Signed For (1 working day)</option> <option value="UK_RoyalMailNextDay">Royal Mail Tracked 24 (1 working day)</option> <option value="UK_RoyalMail24">Royal Mail 24 (1 working day)</option> <option value="UK_CollectPlusStandard">Collect+ Standard (2 working days)</option> <option value="UK_Parcelforce48">Parcelforce 48 (1 to 2 working days)</option> <option value="UK_OtherCourier48">Other 48 Hour Courier (1 to 2 working days)</option> <option disabled>Express services</option> <option value="UK_RoyalMailSpecialDeliveryNextDay">Royal Mail Special Delivery (TM) 1:00 pm (1 working day)</option> <option value="UK_RoyalMailSpecialDelivery9am">Royal Mail Special Delivery (TM) 9:00 am (1 working day)</option> <option value="UK_Parcelforce24">Parcelforce 24 (1 working day)</option> <option value="UK_OtherCourier24">Other 24 Hour Courier (1 working day)</option> <option disabled>Services from outside UK</option> <option value="UK_EconomyShippingFromOutside">Economy Delivery from outside UK (10 to 22 working days)</option> <option value="StandardDeliveryfromOutsideUKwithRoyalMail">Standard Delivery from outside UK with Royal Mail (7 to 13 working days)</option> <option value="UK_StandardShippingFromOutside">Standard Delivery from outside UK (4 to 10 working days)</option> <option value="UK_ExpeditedShippingFromOutside">Express Delivery from outside UK (1 to 3 working days)</option> <option value="UK_FedExIntlEconomy">FedEx International Economy (3 to 4 working days)</option> <option value="UK_TntIntlExp">TNT International Express (2 to 3 working days)</option> <option value="UK_TrackedDeliveryFromAbroad">Tracked delivery from outside UK (2 to 5 working days)</option> <option disabled>Collection</option> <option value="UK_CollectInPerson">Collection in Person </option> </select> </li> <li>Postage Cost*:</br> <input type="text" name="postage_cost"> </li> </ul> <ul> <li>Upload Photo:</br> <input id="text" type="text" name="upload_photo"> </li> <li><input type="checkbox" name="rotate" value="10"/><strong>For 10 credits, you can have your listing displayed on our homepage on a rotation basis. </strong> </li> <li> <input type="submit" value="List Item"></li> </ul> </form> <script type="text/javascript" src="saleSpecies.js"></script> <?php include 'includes/overall/footer.php'; } } } }?> Thanks aquaman Quote Link to comment Share on other sites More sharing options...
jcbones Posted October 5, 2014 Share Posted October 5, 2014 Just as a note, perhaps it will help in the future: if ($credits <= 0) { //not enough credits - show message and redirect echo "You have no remaining credits. You will be redirected to purchase more."; header( "Refresh:5; url=purchase.php", true, 303); exit(); } else { The "else" statement is not needed here. As you will be exiting the script if the "if" statement does run. So the else will never be reached. Just less bracketing to worry with. Quote Link to comment Share on other sites More sharing options...
Barand Posted October 5, 2014 Share Posted October 5, 2014 I mean isnt that what they are for? You mean to do the work for those too lazy to do it themselves? You already knew the solution to the problem. I see from your final code that you really were too idle to take the advice on correct code indenting to find the error yourself <?php include 'includes/overall/footer.php';}}}}?> 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.