Jump to content

problem to call and update


baby83

Recommended Posts

i have this code...

 

but i dont know how to call and update it. can anyone help me?

 

<?

if(!isset($_POST['npop'])){

// this is where the user will select how many pops to insert

?>

<form method="post">

<select name="npop">

<option value="1" selected>1</option>

<option value="2">2</option>

<option value="3">3</option>

<option value="4">4</option>

<option value="5">5</option>

</select>

<input type="submit" value="Continue">

</form>

<?

} else {

if(!isset($_POST['pop'])){

$pop = $_POST['npop'];

// when the user has selected the N number of pops

// its time to create the N input elements

?>

<form method="post">

<input type="hidden" name="npop" value="<?=$pop;?>">

<input type="hidden" name="pop" value="1">

<?

for($i = 1;$i <= $pop; $i++){

echo "<h3>Pop $i</h3>";

 

// now comes the 5 input elements..

// add them as u like naming them in the following pattern,

// or whatever prefix

?>

Element 1 : <input type="text" name="a<?=$i;?>" value=""><br />

Element 2 : <input type="text" name="b<?=$i;?>" value=""><br />

Element 3 : <textarea name="c<?=$i;?>"></textarea><br />

Element 4 : <select name="d<?=$i;?>">

<option value="1">Something</option>

<option value="2">Something</option>

</select><br />

Element 5 : <input type="radio" name"e<?=$i;?>" value="1" checked>Something

<input type="radio" name"e<?=$i;?>" value="2">Something <br />

<?

}

?>

<input type="Submit" value="Submit Form">

</form>

<?

} else {

$pop = $_POST['npop'];

 

// when the user has submitted the pops,

// they will be inserted to N rows in the table.

 

@mysql_connect("localhost", "username", "password");

@mysql_select_db("dbname");

 

for($i = 1; $i <= $pop; $i++){

$a = $_POST['a'.$i]; $b = $_POST['b'.$i]; $c = $_POST['c'.$i];

$d = $_POST['d'.$i]; $e = $_POST['e'.$i];

$sql = "INSERT INTO table VALUES('$a', '$b', '$c', '$d', '$e')";

mysql_query($sql) or die(mysql_error());

}

 

echo "POPs were recorded. Thank you";

 

}

}

?>

Link to comment
https://forums.phpfreaks.com/topic/116179-problem-to-call-and-update/
Share on other sites

ok... actually this is my second step. the first step is... the user need to fill a register form... the form contains identity_number and so on. i want to insert (identity_number) into two tables (personal and education).

then i have a link for user to click if they want to continue. they need to search the identity_number and the details come out. so... the user must select the value of 'pop' for their education (that will insert into education table). if they have 2 types of education, they will select '2'. so the next page will show two same form.

the problem is, in education table,the first row shows data (identity_number) when i register. so, when i fill the education form... it insert to the next row. but what i want is to update the first and so on...

can anybody understand my problem and help me?  :(

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.