FRIHOSTFORUMSFAQTOSBLOGSDIRECTORY
You are invited to Log in or Register a Frihost Account!

10 datas from a form to next page

 


pollux1er
Hi everybody. I want to take from 10 fields times two, the names and the firstnames. How to send that datas to the next page? Of course i have tried something but it does not work. YThis is the script :"

the file form.php

<html>
<head><title></title></head>
<body>
<form action="soumet.php" method=post>
<?
settype($nbnom, "integer");
$nbnom = 10;
for ($i=1; $i<=$nbnom; $i++) {?>
Prenom : <input name="prenom[]" type="text">
Nom : <input name="nom[]" type="text">
<br>
<?
}
?>

<br>
<input type="submit">
</form>

</body>
</html>

The file soumet.php


<html>
<head><title></title></head>
<body>
<?

settype($nom, "string");
settype($prenom, "string");

for
($i=1; $i<=count($nom); $i++)
{
$nom = $nom[$i];
$prenom = $prenom[$i];
echo("Nom : $nom Prenom : $prenom <br>");
}

?>

</body>
</html>

What can be the matter on these codes?
jabapyth
you dont need to do all that "set_type"ing -- php is loosely typed.
To get variable from a form in php, you need to use the $GET_ or $POST_ variables:
in your case (since you did method=post) i suggest doing this:
Code:
The file soumet.php


<html>
<head><title></title></head>
<body>
<?
$nom = $POST_["nom[]"];
$prenom = $POST_["prenom[]"];
for
($i=1; $i<=count($nom); $i++)
{
$nom = $nom[$i];
$prenom = $prenom[$i];
echo("Nom : $nom Prenom : $prenom <br>");
}

?>

</body>
</html>

Then it should work
imagefree
i cant understand why you are using this loop the this way



Code:
for
($i=1; $i<=count($nom); $i++)
{
$nom = $nom[$i];
$prenom = $prenom[$i];
echo("Nom : $nom Prenom : $prenom <br>");
}


I recommend you the following code:

For file form.php

Code:

<html><head><title></title></head><body>

<form action="soumet.php" method=post>
<?php   //remember to use "php" here.
/*settype($nbnom, "integer");  it is useless*/
$nbnom = 10;
for ($i=0; $i<$nbnom; $i++)
{?>
Prenom : <input name="prenom[<?php echo $i; ?>]" type="text">
Nom : <input name="nom[<?php echo $i; ?>]" type="text">
<br>
<?php
}
?>
//I dont know weather breaking the code in the above way should work or not. I have never broken a loop.
<br>
<input type="submit">
</form>
</body></html>


For the file soumet.php


Code:

<html><head><title></title></head><body>
<?php

/*
settype($nom, "string");
settype($prenom, "string"); //Useless block of code
*/

$nom=$_POST["nom"];
$prenom=$_POST["prenom"];

for($i=0; $i<=count($nom);$i++)
{
echo "Nom: {$nom[$i]} Prenom : {$prenom[$i]}";
}
?>
</body></html>



I think it should work now.
For more help, we are here to help you.
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2007 Frihost, forums powered by phpBB.