Jump to content

[SOLVED] form help cheers array probs


redarrow

Recommended Posts

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>

Link to comment
Share on other sites

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'];

}

}

?>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

 

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>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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>

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.