redarrow Posted December 8, 2008 Share Posted December 8, 2008 Advance thank you..... A user has to choose 5 numbers for this game, each time the user choose to see 1 - 3 numbers they got to add 1 off them numbers to a basket, they do this 5 times so the basket gets 5 numbers.. how do i add session's to the ball numbers.... to be added to a basket...... <center><h1>The Ball Game</h1></center> <?php if(isset($_POST['number_of_balls'])){ $balls=$_POST['balls']; echo " <form method='POST' action='".$_SERVER['PHP_SELF']."'> <center>Please shuffle balls 5 times and add a number to the basket each time!</center> <br><br> <center>You have choose $balls number off balls!<br><br>Plase add 1 ball to the basket!</center> <br>"; ?> <?php for($i=0; $i<$balls; $i++){ $num=rand(0000,9999); echo"<center><br><br><input type='hidden' name='my_balls' vlaue='$num'>$num<br><br></center>"; } } ?> <center> <form method="POST" action="<?php $_SERVER['PHP_SELF'] ?>"> <select name="balls"> <?php for($i=1; $i<4; $i++){ echo "<option value='$i'>$i</option>"; } ?> </select> <br><br> <input type="submit" name="number_of_balls"> </center> Link to comment https://forums.phpfreaks.com/topic/136040-solved-using-sessions-with-a-simple-game/ Share on other sites More sharing options...
redarrow Posted December 8, 2008 Author Share Posted December 8, 2008 i tried it this way for the session to be catched with the relevant number why dont it work please........ <center><h1>The Ball Game</h1></center> <?php session_start(); $my_balls=$_POST['my_balls']; if(isset($_POST['add_ball'])){ $my_balls=$_POST['my_balls']; if(empty($_SESSION['balla'])){ $_SESSION['balla']=$my_balls; }elseif(empty($_SESSION['ballb'])){ $_SESSION['ballb']=$my_balls; }elseif(empty($_SESSION['ballc'])){ $_SESSION['ballc']=$my_balls; }elseif(empty($_SESSION['ballc'])){ $_SESSION['ballc']=$my_balls; }elseif(empty($_SESSION['balld'])){ $_SESSION['balld']=$my_balls; }elseif(empty($_SESSION['balld'])){ $_SESSION['balld']=$my_balls; }elseif(empty($_SESSION['balle'])){ $_SESSION['balle']=$my_balls; } echo " ".$_SESSION['balla']." <br> ".$_SESSION['ballb']." <br> ".$_SESSION['ballc']." <br> ".$_SESSION['balld']." <br> ".$_SESSION['balle']." "; } if(isset($_POST['number_of_balls'])){ $balls=$_POST['balls']; echo " <form method='POST' action='".$_SERVER['PHP_SELF']."'> <center>Please shuffle balls 5 times and add a number to the basket each time!</center> <br><br> <center>You have choose $balls number off balls!<br><br>Plase add 1 ball to the basket!</center> <br>"; ?> <?php for($i=0; $i<$balls; $i++){ $num=rand(0000,9999); echo "<form method='POST' action='".$_SERVER['PHP_SELF']."'"; echo"<center><br><br><input type='hidden' name='my_balls' vlaue='$num'>$num <br><input type='submit' name='add_ball' value='Add ball'> <br><br></center>"; echo"</form>"; } } ?> <center> <form method="POST" action="<?php $_SERVER['PHP_SELF'] ?>"> <select name="balls"> <?php for($i=1; $i<4; $i++){ echo "<option value='$i'>$i</option>"; } ?> </select> <br><br> <input type="submit" name="number_of_balls"> </center> Link to comment https://forums.phpfreaks.com/topic/136040-solved-using-sessions-with-a-simple-game/#findComment-709304 Share on other sites More sharing options...
redarrow Posted December 8, 2008 Author Share Posted December 8, 2008 This was for fun, A game that added the number's to a barsket, Then the abilty to delete the numbers from the basket. was to learn session properly well good ye haaaaaaaaaaaaa <center><h1>The Ball Game</h1></center> <?php session_start(); if(isset($_POST['add_ball'])){ $my_balls=$_POST['my_balls']; if(empty($_SESSION['balla'])){ $_SESSION['balla']=$my_balls; }elseif(empty($_SESSION['ballb'])){ $_SESSION['ballb']=$my_balls; }elseif(empty($_SESSION['ballc'])){ $_SESSION['ballc']=$my_balls; }elseif(empty($_SESSION['ballc'])){ $_SESSION['ballc']=$my_balls; }elseif(empty($_SESSION['balld'])){ $_SESSION['balld']=$my_balls; }elseif(empty($_SESSION['balld'])){ $_SESSION['balld']=$my_balls; }elseif(empty($_SESSION['balle'])){ $_SESSION['balle']=$my_balls; } } if(isset($_POST['number_of_balls'])){ $balls=$_POST['balls']; echo " <form method='POST' action='".$_SERVER['PHP_SELF']."'> <center>Please shuffle balls 5 times and add a number to the basket each time!</center> <br><br> <center>You have choose $balls number off balls!<br><br>Plase add 1 ball to the basket!</center> <br> <center> Your Basket! <br><br> ball1 ".$_SESSION['balla']." <br> ball2 ".$_SESSION['ballb']." <br> ball3 ".$_SESSION['ballc']." <br> ball4 ".$_SESSION['balld']." <br> ball5 ".$_SESSION['balle']." "; echo "<br><a href=' ".$_SERVER['PHP_SELF']."?delete=barsket'>delete barsket</a><br> </center>"; ?> <?php if($_GET['delete']=="barsket"){ unset($_SESSION['balla']); unset($_SESSION['ballb']); unset($_SESSION['ballc']); unset($_SESSION['balld']); unset($_SESSION['balle']); session_destroy(); } ?> <?php for($i=0; $i<$balls; $i++){ $num=rand(0000,9999); echo "<form method='POST' action='".$_SERVER['PHP_SELF']."'"; echo"<center><br><br><input type='hidden' name='my_balls' value='$num'>$num <br><input type='submit' name='add_ball' value='Add ball'> <br><br></center>"; echo"</form>"; } } ?> <center> <form method="POST" action="<?php $_SERVER['PHP_SELF'] ?>"> <select name="balls"> <?php for($i=1; $i<4; $i++){ echo "<option value='$i'>$i</option>"; } ?> </select> <br><br> <input type="submit" name="number_of_balls"> </center> Link to comment https://forums.phpfreaks.com/topic/136040-solved-using-sessions-with-a-simple-game/#findComment-709320 Share on other sites More sharing options...
Yesideez Posted December 8, 2008 Share Posted December 8, 2008 First, if you want the numbers to be shown as the user chooses them you'll need to have Javascript running for that. Or... present the user with 5 text input boxes and a submit button when user clicks submit the 5 numbers are checked if any are invalid (ie. two are the same) display an error message and start over If they got this far the numbers are all valid and you'll need to assign them to sesion vars $_SESSION['ball1']=$ball1; $_SESSION['ball2']=$ball2; $_SESSION['ball3']=$ball3; $_SESSION['ball4']=$ball4; $_SESSION['ball5']=$ball5; Link to comment https://forums.phpfreaks.com/topic/136040-solved-using-sessions-with-a-simple-game/#findComment-709331 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.