Jump to content

Recommended Posts

well here's everythin

i want to know how i can keep a value into a form while reloading the same page with different values to allow me to add multiple entries to the db

 

here's my code :

 

<html>
<head>
	<title>add an entry</title>
</head>
<body>

<form action="add_mutiple_entries.php?n=<?php echo $_GET['n']; ?>" method="post">

The 1 query already active<br />
Name 1: <input type="text" name="name" value="" /><br />
Age 1: <input type="text" name="age" value=""/><br />
<br />

<?php 
	$i = 1;
	while ( $i <= $_GET['n'] - 1 )
	{
	$i++;

	echo '<input type="checkbox" name="add' . $i . '" value="' . $i . '"/>  <span>The ' . $i . ' query</span><br />';
	echo "\n";
	echo 'Name ' . $i . ' : <input type="text" name="name' . $i . '" /><br />';
	echo "\n";
	echo 'Age ' . $i . ' : <input type="text" name="age' . $i . '" /><br />';
	echo "\n";
	echo "<br />";
	}
?>

<br />


<br />


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

<form action="?">
<label>Add more</label> <select name="n">
<?php 
	if ( $_GET['n'] == 0) {
		$nb = 1;
	} else {
		$nb = 0;
	}
	$n = $_GET['n'] + $nb; 

	$i = $n;
	while ( $i <= 20 - 1)
	{
	$i++;
	$d = $i - 1;
	echo '<option value="' . $i  . '">' . $d . '</option>';
	echo "\n";
	}
	?>
</select>
<input type="submit" value="add" />
</form>
</body>
</html>

 

help ^^

it does not work

what i understood from u is :

<?php 
	$_SESSION['name'] = $_POST['name'];
	$_SESSION['age'] = $_POST['age'];
?>

 

and call the session name in the value attribute

 

but when i click the " add " button there i see nothing in the form all empty :s

of course I did it ^^

 

if u see my code well u'll see that i have 2 forms and 2 buttons so when i click the submit button it submits the query very well and when i click the add button it opens the same page with different value to allow me to add more fields but it does not keep the other form's values..

oh, I see what you are talking about. Well, there isn't a good way of doing this without using JavaScript.

Your going to need to grab the input values from your main form and place em in some hidden fields in the add form. One hidden field foreach input in the other form. Then, when they submit the add from, the values of the other from will be in the query string where then you can use em like $_GET['temp_name'] or something like that.

Can you post your current code (the one you modified to use sessions?)? Thanks.

yes here it is :

<?php
session_start();
?>
<html>
<head>
	<title>add multiple entries !!</title>
</head>
<body>

<form action="add_mutiple_entries.php?n=<?php echo $_GET['n']; ?>" method="post" name="myForm">

The 1 query already active<br />
Name 1: <input type="text" name="name" value="" />  

<br />
Age 1: <input type="text" name="age" value="<?php echo $_SESSION['age']; ?>"/><br />
<?php 
	$_SESSION['name'] = $_POST['name'];
	$_SESSION['age'] = $_POST['age'];
?>
<br />

<br />
<?php 
	$i = 1;
	while ( $i <= $_GET['n'] - 1 )
	{

	$i++;
?>
<?php	

	echo '<input type="checkbox" name="add' . $i . '" value="' . $i . '"/>  <span>The ' . $i . ' query</span><br />';

	echo '<div id="layer1">';
	echo "\n";
	echo 'Name ' . $i . ' : <input type="text" name="name' . $i . '" /><br />';
	echo "\n";
	echo 'Age ' . $i . ' : <input type="text" name="age' . $i . '" /><br />';
	echo "\n";
	echo "</div>";
	echo '<br />';

	}
?>

<br />


<br />


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

<form action="?" name="Add">
<label>Add more</label> <select name="n">
<?php 
	if ( $_GET['n'] == 0) {
		$nb = 1;
	} else {
		$nb = 0;
	}
	$n = $_GET['n'] + $nb; 

	$i = $n;
	while ( $i <= 20 - 1)
	{
	$i++;
	$d = $i - 1;
	echo '<option value="' . $i  . '">' . $d . '</option>';
	echo "\n";
	}
	?>
</select>
<input type="submit" value="add" />
</form>

</body>
</html>	

 

thanks, really need help with this..

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.