baby83 Posted July 23, 2008 Share Posted July 23, 2008 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"; } } ?> Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted July 23, 2008 Share Posted July 23, 2008 What do you mean, call and update it? Quote Link to comment Share on other sites More sharing options...
Entanio Posted July 23, 2008 Share Posted July 23, 2008 } else { if(!isset($_POST['pop'])){ You are contradicting youreself here :S You are saying "'npop' has been posted, now if 'pop' hasn't been posted do whatever". Quote Link to comment Share on other sites More sharing options...
Entanio Posted July 23, 2008 Share Posted July 23, 2008 for($i = 1;$i <= $pop; $i++){ I don't know but I think you should put: $i=0; while($i < $pop){ ... $i++ } Quote Link to comment Share on other sites More sharing options...
Entanio Posted July 23, 2008 Share Posted July 23, 2008 } else { if(!isset($_POST['pop'])){ You are contradicting youreself here :S You are saying "'npop' has been posted, now if 'pop' hasn't been posted do whatever". Sorry, My mistake, I misunderstood something. Quote Link to comment Share on other sites More sharing options...
baby83 Posted July 23, 2008 Author Share Posted July 23, 2008 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? 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.