First of all I would like to say this is my first script and if you see any problems please tell me besides my issues... lol I have two issues: 1.) My if statment in my function addCart will not work for some reason is my coding wrong? 2.) My code output is all bunched up can I change that so it outputs cleaner (I.E. One tag per line or use of line brakes) <?php // Define varables // $howmany = $_POST['howmany']; $addauthor = $_POST['addauthor']; $addtitle = $_POST['addtitle']; $addcompilation = $_POST['addcompilation']; // Product Button output Function // function addCart($id,$name,$descript,$price) { echo '<input name="item_name_' . $id . '" type="hidden" value="' . $name . '"/>'; echo '<input name="item_description_' . $id . '" type="hidden" value="' . $descript . '"/>'; if ($howmany > "1") echo '<input name="item_quantity_' . $id . '" type="hidden" value="' . $howmany . '"/>'; else echo '<input name="item_quantity_' . $id . '" type="hidden" value="1"/>'; echo '<input name="item_price_' . $id . '" type="hidden" value="' . $price . '"/>'; echo '<input name="item_currency_' . $id . '" type="hidden" value="USD"/>'; } // Check Data // echo '<hr />'; echo 'Form data check' . '<br />'; echo 'howmany= ' . $howmany . '<br />'; echo 'addauthor= ' . $addauthor . '<br />'; echo 'addtitle= ' . $addtitle . '<br />'; echo 'addcompilation= ' . $addcompilation . '<br />'; echo '<hr />' . '<br /><br />'; // Print Requested // if ($howmany == "1") echo 'Please download all pdf files and fill out completly before uploading or faxing.' . '<br />'; elseif ($howmany == "2") echo 'Please download all pdf files and fill out completly twice before uploading or faxing.' . '<br />'; elseif ($howmany == "3") echo 'Please download all pdf files and fill out completly three times before uploading or faxing.' . '<br />'; if ($addauthor == "yes") echo 'AUTHOR PDF FILE' . '<br />'; if ($addtitle == "yes") echo 'TITLE PDF FILE' . '<br />'; if ($addcompilation == "yes") echo 'COMPILATION PDF FILE' . '<br />'; // Print Buy Now Button echo '<br /><br />'; echo '<form action="https://checkout.google.com/cws/v2/Merchant/304544305785286/checkoutForm" id="BB_BuyButtonForm" method="post" name="BB_BuyButtonForm">'; addCart("1","Copyright Service","Copyright Service fee not including filing fee","49.0"); if ($addauthor == "yes") addCart("2","Add Author","You requested to add author form","10.0"); if ($addtitle == "yes") addCart("3","Add Title","You requested to add title form","5.0"); if ($addcompilation == "yes") addCart("4","Add Compilation","You requested the add Compliation form","5.0"); echo '<input name="_charset_" type="hidden" value="utf-8"/>'; echo '<input alt="" src="https://checkout.google.com/buttons/buy.gif?merchant_id=304544305785286&w=117&h=48&style=trans&variant=text&loc=en_US" type="image"/>'; echo '</form>'; ?> Code (markup):
You mean the problem is resolved? If not, you are missing an opening brace { for your conditional. if ($howmany > "1") { echo ... PHP: Your other problem can be solved by using "\n" in your echo calls.
http://formatter.gerbenvv.nl/version3/index.php I find this php formatter is a great online tool. You said you bunched up a bunch of stuff, but I do not really see it. Other then cleaning up your variables and watching out for sql and xss injections in your script. All is good I think. <?php // Define varables // $howmany = $_POST['howmany']; $addauthor = $_POST['addauthor']; $addtitle = $_POST['addtitle']; $addcompilation = $_POST['addcompilation']; // Product Button output Function // function addCart($id, $name, $descript, $price) { echo '<input name="item_name_' . $id . '" type="hidden" value="' . $name . '"/> <input name="item_description_' . $id . '" type="hidden" value="' . $descript . '"/>'; if ($howmany > "1") echo '<input name="item_quantity_' . $id . '" type="hidden" value="' . $howmany . '"/>'; else echo '<input name="item_quantity_' . $id . '" type="hidden" value="1"/>'; echo '<input name="item_price_' . $id . '" type="hidden" value="' . $price . '"/> <input name="item_currency_' . $id . '" type="hidden" value="USD"/>'; } // Check Data // echo '<hr /> Form data check' . '<br /> howmany= ' . $howmany . '<br /> addauthor= ' . $addauthor . '<br /> addtitle= ' . $addtitle . '<br /> addcompilation= ' . $addcompilation . '<br /> <hr /> <br /><br />'; // Print Requested // if ($howmany == "1") echo 'Please download all pdf files and fill out completly before uploading or faxing.' . '<br />'; elseif ($howmany == "2") echo 'Please download all pdf files and fill out completly twice before uploading or faxing.' . '<br />'; elseif ($howmany == "3") echo 'Please download all pdf files and fill out completly three times before uploading or faxing.' . '<br />'; if ($addauthor == "yes") echo 'AUTHOR PDF FILE' . '<br />'; if ($addtitle == "yes") echo 'TITLE PDF FILE' . '<br />'; if ($addcompilation == "yes") echo 'COMPILATION PDF FILE' . '<br />'; // Print Buy Now Button echo '<br /><br /> <form action="https://checkout.google.com/cws/v2/Merchant/304544305785286/checkoutForm" id="BB_BuyButtonForm" method="post" name="BB_BuyButtonForm">'; addCart("1", "Copyright Service", "Copyright Service fee not including filing fee", "49.0"); if ($addauthor == "yes") addCart("2", "Add Author", "You requested to add author form", "10.0"); if ($addtitle == "yes") addCart("3", "Add Title", "You requested to add title form", "5.0"); if ($addcompilation == "yes") addCart("4", "Add Compilation", "You requested the add Compliation form", "5.0"); echo '<input name="_charset_" type="hidden" value="utf-8"/> <input alt="" src="https://checkout.google.com/buttons/buy.gif?merchant_id=304544305785286&w=117&h=48&style=trans&variant=text&loc=en_US" type="image"/> </form>'; ?> PHP:
it doesn't seem to matter about brace's unless its multiple lines for that one if command is that wrong?