craigafer Posted September 12, 2010 Share Posted September 12, 2010 well, here's my problem, im new to php, i currently working on this mini online shop the picture will explain it well, i've managed to create the receipt per shop but i cant do the receipt of the overall shopping here is my code: <html> <head> <title>My Shop 4</title> <script type="text/javascript"> function gohome() { window.open("receipt.php","_self"); } function changeshop() { window.open("home.html","_self"); } </script> </head> <body> <form action="" method="POST"> <input type="checkbox" name="prod1" id="prod1"\ value=10>Product 1 10.00php<br> <input type="checkbox" name="prod2" id="prod2"\ value=20>Product 2 20.00php<br> <input type="checkbox" name="prod3" id="prod3"\ value=30>Product 3 30.00php<br> <input type="checkbox" name="prod4" id="prod4"\ value=40>Product 4 40.00php<br> <input type="checkbox" name="prod5" id="prod5"\ value=50>Product 5 50.00php<br> <input type="submit" name="submit" id="submit" value="Buy!!"><br> <?php $det = 4; require("../Labphp/lab.php"); shop($det); ?> </form> </body> </html> and here's the php part <?php $total = 0; $total3 = 0; $total4 = 0; $recent ="HAHAHA"; global $total,$total3,$total4,$recent; ?> <?php function shop($num) { $value1 = $_POST['prod1']; $value2 = $_POST['prod2']; $value3 = $_POST['prod3']; $value4 = $_POST['prod4']; $value5 = $_POST['prod5']; $sum=0; $sum = $value1 + $value2 + $value3 + $value4 + $value5; if($sum!=0) { echo "Selected Products<br>"; echo "Product Name       Price<br>"; if($value1==true) { echo "Product 1              10.php<br>"; } if($value2==true) { echo "Product 2              20.php<br>"; } if($value3==true) { echo "Product 3              30.php<br>"; } if($value4==true) { echo "Product 4              40.php<br>"; } if($value5==true) { echo "Product 5              50.php<br>"; } echo "Total                     $sum php<br>"; if($num==4) { $total4=$sum; $recent.="Shop 4                  $total4 php<br>"; } else if($num==3) { $total3=$sum; $recent.="Shop 3                  $total3 php<br>"; } $total = $total4 + $total3; echo "$recent              $total"; echo "<input type='button' name='go' id='go' value='Choose Another Shop' onclick='javascript:changeshop();'>"; echo "<input type='button' name='end' id='end' value='End Shopping' onclick='javascript:gohome();'>"; } } function getshopping() { return $recent; } ?> the receipt code <?php require("../Labphp/lab.php"); ?> <html> <head> <title>Official Receipt</title> </head> <body <?php echo $_REQUEST["'$recent'"]; ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/213215-noob-here-need-some-help/ Share on other sites More sharing options...
trq Posted September 12, 2010 Share Posted September 12, 2010 Where exactly are you stuck? Quote Link to comment https://forums.phpfreaks.com/topic/213215-noob-here-need-some-help/#findComment-1110212 Share on other sites More sharing options...
craigafer Posted September 12, 2010 Author Share Posted September 12, 2010 the official receipt of the shops the receipt code it doesnt print a thing Quote Link to comment https://forums.phpfreaks.com/topic/213215-noob-here-need-some-help/#findComment-1110215 Share on other sites More sharing options...
rwwd Posted September 12, 2010 Share Posted September 12, 2010 Hi there, <?php //change this to without quotes & change from $_REQUEST to POST or GET if(isset($_POST[$recent])){ echo $_POST[$recent]; } else{ echo "No receipt has been set to print!"; } ?> This is why it's not printing anything! Change the request to get or post, whichever you are using as there are security issues surrounding $_REQUEST at present, also you need to check to see if it's set before it's requested to screen! And secondly, the function getshopping() doesn't have anything passed into it, so returning $recent; from it doesn't actually do anything so far as I can tell, you need to pass something as a parameter into the function to be able to return something from it, unless the function (by design) does all it's functionality without parameters being passed to it eg:- function Bark(){ return $myDog = "My dog wants feeding!"; } echo Bark(); //will output:- My dog wants feeding! Cheers, Rw Quote Link to comment https://forums.phpfreaks.com/topic/213215-noob-here-need-some-help/#findComment-1110218 Share on other sites More sharing options...
craigafer Posted September 12, 2010 Author Share Posted September 12, 2010 <?php require("../Labphp/lab.php"); ?> <html> <head> <title>Official Receipt</title> </head> <body <?php //change this to without quotes & change from $_REQUEST to POST or GET if(isset($_POST[$recent])){ echo $_POST[$recent]; } else{ echo "No receipt has been set to print!"; } ?> </body> </html> ] ive tried this but nothing prints too the two shops and receipts are different file though i got another question if(isset($_POST[$recent])) <--- whats this for? i always see this but idk whats this for Quote Link to comment https://forums.phpfreaks.com/topic/213215-noob-here-need-some-help/#findComment-1110221 Share on other sites More sharing options...
rwwd Posted September 12, 2010 Share Posted September 12, 2010 Hi there, i got another question if(isset($_POST[$recent])) <--- whats this for? i always see this but idk whats this for Simply means:- if(isset($_POST[$recent])) If it is set (the variable/global/array that you are referencing) then do something with it else do something else with it. See this from the manual I have no idea then why it's not working, but it seems to me like you need to see how you have your functions interacting and find out where $recent should be being populated... Cheers, Rw Quote Link to comment https://forums.phpfreaks.com/topic/213215-noob-here-need-some-help/#findComment-1110228 Share on other sites More sharing options...
craigafer Posted September 12, 2010 Author Share Posted September 12, 2010 got it someone told me i should put sessions any comments on that? Quote Link to comment https://forums.phpfreaks.com/topic/213215-noob-here-need-some-help/#findComment-1110232 Share on other sites More sharing options...
craigafer Posted September 12, 2010 Author Share Posted September 12, 2010 well it worked with sessions codes for shop4 (codes for shop3 is the same i just edited the $det to 3) <?php session_start(); ?> <html> <head> <title>My Shop 4</title> <script type="text/javascript"> function gohome() { window.open("receipt.php","_self"); } function changeshop() { window.open("home.html","_self"); } </script> </head> <body> <form action="" method="POST"> <input type="checkbox" name="prod1" id="prod1"\ value=10>Product 1 10.00php<br> <input type="checkbox" name="prod2" id="prod2"\ value=20>Product 2 20.00php<br> <input type="checkbox" name="prod3" id="prod3"\ value=30>Product 3 30.00php<br> <input type="checkbox" name="prod4" id="prod4"\ value=40>Product 4 40.00php<br> <input type="checkbox" name="prod5" id="prod5"\ value=50>Product 5 50.00php<br> <input type="submit" name="submit" id="submit" value="Buy!!"><br> <?php $det = 4; require("../Labphp/lab.php"); shop($det); ?> </form> </body> </html> php codes <?php session_start(); ?> <?php $total = 0; $total3 = 0; $total4 = 0; $recent =""; global $total,$total3,$total4,$recent; ?> <?php function shop($num) { $value1 = $_POST['prod1']; $value2 = $_POST['prod2']; $value3 = $_POST['prod3']; $value4 = $_POST['prod4']; $value5 = $_POST['prod5']; $sum=0; $sum = $value1 + $value2 + $value3 + $value4 + $value5; if($sum!=0) { echo "Selected Products<br>"; echo "Product Name       Price<br>"; if($value1==true) { echo "Product 1              10.php<br>"; } if($value2==true) { echo "Product 2              20.php<br>"; } if($value3==true) { echo "Product 3              30.php<br>"; } if($value4==true) { echo "Product 4              40.php<br>"; } if($value5==true) { echo "Product 5              50.php<br>"; } echo "Total                     $sum php<br>"; if($num==4) { $total4=$sum; $recent.="Shop 4                  $total4 php<br>"; } else if($num==3) { $total3=$sum; $recent .="Shop 3                  $total3 php<br>"; } $total = $total4 + $total3; $_SESSION['overall'] += $total; $_SESSION['history'] .= $recent; echo "<input type='button' name='go' id='go' value='Choose Another Shop' onclick='javascript:changeshop();'>"; echo "<input type='button' name='end' id='end' value='End Shopping' onclick='javascript:gohome();'>"; } } ?> codes for receipt <?php session_start(); ?> <?php require("../Labphp/lab.php"); echo "<br>".$_SESSION['history']; echo "Total ".$_SESSION['overall']; ?> <html> <head> <title>Official Receipt</title> </head> <body> </body> </html> its working nao!! thnx btw Quote Link to comment https://forums.phpfreaks.com/topic/213215-noob-here-need-some-help/#findComment-1110239 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.