redarrow Posted October 2, 2008 Share Posted October 2, 2008 why dosent this work with form array please <?php if(isset($_POST['submit'])){ for($i=0; $i<count($a[]); $i++){ echo $a[$i]; } } ?> <form method="POST" action="form.php"> <br> <input type="text" name="a[]"> <br> <br> <input type="text" name="a[]" > <br> <br> <input type="text" name="a[]" > <br> <br> <input type="submit" name="submit" value="SEND!"> </form> Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted October 2, 2008 Share Posted October 2, 2008 That doesn't make sense. Are you trying something like this? <?php if(isset($_POST['submit'])){ for($i=0; $i<count($_POST['a']); $i++){ echo $_POST['a'][$i]."<br />"; } } ?> Quote Link to comment Share on other sites More sharing options...
ratcateme Posted October 2, 2008 Share Posted October 2, 2008 when using dealing with arrays you want to use foreach loops as they are more effective at moving through arrays but your code should be like this <?php if(isset($_POST['submit'])){ foreach($_POST['a'] as $b){ echo $b; } } ?> Scott. Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 2, 2008 Author Share Posted October 2, 2008 this worked <?php if(isset($_POST['submit'])){ foreach($_POST['a'] as $b){ echo $b; } } ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 2, 2008 Author Share Posted October 2, 2008 why dosent this work please........ <?php session_start(); if(isset($_POST['submit'])){ foreach($_POST['a'] as $b){ $_SESSION['a']=$b[0]; $_SESSION['b']=$b[1]; $_SESSION['c']=$b[2]; echo $_SESSION['a']; } } ?> Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 2, 2008 Author Share Posted October 2, 2008 how comes i can not set sessions form an array form! example below......... Quote Link to comment Share on other sites More sharing options...
trq Posted October 2, 2008 Share Posted October 2, 2008 Can you actually describe your problem? Ive said it before but you really ought read the 'howto ask?' link in my signiture. Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 2, 2008 Author Share Posted October 2, 2008 only the ecohed session should be echoed but i can echo them all.... im try to set sessions from a arrayed form.... the form is at the first post set to name a[] <?php session_start(); if(isset($_POST['submit'])){ foreach($_POST['a'] as $b){ $c=explode(' ',$b); $_SESSION['a']="$c[0]"; $_SESSION['b']="$c[1]"; $_SESSION['c']="$c[2]"; echo $_SESSION['a']; } } ?> Quote Link to comment Share on other sites More sharing options...
trq Posted October 2, 2008 Share Posted October 2, 2008 That makes heaps more sense. Bye. Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 2, 2008 Author Share Posted October 2, 2008 here the full code how do you brake the array down to get the sessions to be indevgally used............. when i echo the session out from the posted form the one ecohed session dispalys all the ordered array from the form <?php session_start(); if(isset($_POST['submit'])){ foreach($_POST['a'] as $b){ $c=explode(' ',$b); $_SESSION['a']="$c[0]"; $_SESSION['b']="$c[1]"; $_SESSION['c']="$c[2]"; echo $_SESSION['a']; //this should be set to this >>$_SESSION['a']="$c[0]"; only but echo them all...... } } ?> <form method="POST" action="form.php"> <br> <input type="text" name="a[]"> <br> <br> <input type="text" name="a[]" > <br> <br> <input type="text" name="a[]" > <br> <br> <input type="submit" name="submit" value="SEND!"> </form> Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 2, 2008 Author Share Posted October 2, 2008 why can i not set the session via posting from a form................... simple example................. <?php session_start(); if(isset($_POST['submit'])){ $_SESSION['a']=$_POST['cat']; $_SESSION['b']=$_POST['dog']; $_SESSION['c']=$_POST['pig']; echo $_SESSION['a']; } ?> <form method="POST" action="form.php"> <br> <input type="text" name="pig"> <br> <br> <input type="text" name="dog" > <br> <br> <input type="text" name="cat" > <br> <br> <input type="submit" name="submit" value="SEND!"> </form> Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 2, 2008 Author Share Posted October 2, 2008 non array way working need the same way with arrays....... <?php session_start(); if(isset($_POST['submit'])){ $cat=$_POST['cat']; $dog=$_POST['dog']; $pig=$_POST['pig']; $_SESSION['a']=$cat; $_SESSION['b']=$dog; $_SESSION['c']=$pig; echo" <br> {$_SESSION['a']} <br> {$_SESSION['b']} <br> {$_SESSION['c']} "; } ?> <form method="POST" action="form.php"> <br> <input type="text" name="pig"> <br> <br> <input type="text" name="dog" > <br> <br> <input type="text" name="cat" > <br> <br> <input type="submit" name="submit" value="SEND!"> </form> Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 2, 2008 Author Share Posted October 2, 2008 look above wrong lol the array way.......... <?php session_start(); if(isset($_POST['submit'])){ foreach($_POST['a'] as $b){ $_SESSION['a']=$b[0]; $_SESSION['b']=$b[1]; $_SESSION['c']=$b[2]; echo" <br> {$_SESSION['a']} <br> {$_SESSION['b']} <br> {$_SESSION['c']} "; } } ?> <form method="POST" action="form.php"> <br> <input type="text" name="a[]"> <br> <br> <input type="text" name="a[]" > <br> <br> <input type="text" name="a[]" > <br> <br> <input type="submit" name="submit" value="SEND!"> </form> Quote Link to comment Share on other sites More sharing options...
redarrow Posted October 2, 2008 Author Share Posted October 2, 2008 corrected forgot explode........ array way to set sessions via a form...... <?php session_start(); if(isset($_POST['submit'])){ foreach($_POST['a'] as $b){ $b=explode( ' ', $b); $_SESSION['a']="$b[0]"; $_SESSION['b']="$b[1]"; $_SESSION['c']="$b[2]"; echo" <br> {$_SESSION['a']} <br> {$_SESSION['b']} <br> {$_SESSION['c']} "; } } ?> <form method="POST" action="form.php"> <br> <input type="text" name="a[]"> <br> <br> <input type="text" name="a[]" > <br> <br> <input type="text" name="a[]" > <br> <br> <input type="submit" name="submit" value="SEND!"> </form> non array way to set sessions via a form...... <?php session_start(); if(isset($_POST['submit'])){ $cat=$_POST['cat']; $dog=$_POST['dog']; $pig=$_POST['pig']; $_SESSION['a']=$cat; $_SESSION['b']=$dog; $_SESSION['c']=$pig; echo" <br> {$_SESSION['a']} <br> {$_SESSION['b']} <br> {$_SESSION['c']} "; } ?> <form method="POST" action="form.php"> <br> <input type="text" name="pig"> <br> <br> <input type="text" name="dog" > <br> <br> <input type="text" name="cat" > <br> <br> <input type="submit" name="submit" value="SEND!"> </form> 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.