Eugene Posted April 13, 2006 Share Posted April 13, 2006 I need some serious help. Here are 2 pieces of code from a webpage.[code]function add_msn() {echo "<div class=\"tableborder\"><div class=\"maintitle\">Add members to the Database here</div>";echo "How many members would you like to add?";echo "<form method=\"post\"><select name=\"number\">";for($i = 1; $i <= 100; $i++) {echo "<option value=\"$i\">$i</option>";}echo "</select><br><br><input type=\"submit\" value=\"Submit\" name=\"submit\"><br><br></form>";$number = $_POST['number'];$submit = $_POST['submit'];if($submit) {echo "</div><br></td></tr><tr><td> </td><td valign=\"top\"><div class=\"tableborder\"><form method=\"post\" onsubmit=\"return formValidation(this)\"><div class=\"maintitle\">Enter your Member names here</div><br><br>";for($i = 1; $i <= $number; $i++) {echo "$i) <br>Real Name: <input type=\"text\" name=\"rsid\"><br>MSN Identity: <input type=\"text\" name=\"msnid\"><br>Member Rank:<select name=\"rank\">";mysql_connect("*", "*", "*") or die(mysql());mysql_select_db("*") or die(mysql());$result = mysql_query("SELECT * FROM *")or die(mysql_error());while($row = mysql_fetch_array( $result )) {$dbrank = $row['rank'];echo "<option>$dbrank</option>";}echo "</select><br>";}echo "<input type=\"submit\" name=\"sbtdb\" value=\"Submit MSN list\"> <input type=\"reset\"></form></div>";}[/code]That works fine and so does this:[code]$dbsubmit = $_POST['sbtdb'];$msnid = $_POST['msnid'];$rank = $_POST['rank'];$rsid = $_POST['rsid'];if($dbsubmit) {mysql_connect("*", "*", "*") or die(mysql_error());mysql_select_db("*") or die(mysql_error());mysql_query("INSERT INTO MSN(ID, rsid, msnid, rank) VALUES('', '$rsid', '$msnid', '$rank')")or die(mysql_error());echo "$rsid has been entered into the database!<br>";}[/code]See, all the coding is correct, but everytime on the test page, when I want to enter more than 1 MSN Identity, it only enters the LAST entered one. How can I enter more than one? I've tried arrays, function, thats about all. I don't know what else to do. Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted April 13, 2006 Share Posted April 13, 2006 first off you need to alter the form so that the inputs do not 'overwrite' the previous input name...[code]<?php....$result = mysql_query("SELECT * FROM *")or die(mysql_error());for($i = 1; $i <= $number; $i++) {echo "$i) <br>Real Name: <input type=\"text\" name=\"rsid[]\"><br>MSN Identity: <input type=\"text\" name=\"msnid[]\"><br>Member Rank:<select name=\"rank[]\">";mysql_connect("*", "*", "*") or die(mysql());mysql_select_db("*") or die(mysql());mysql_data_seek($result , 0);while($row = mysql_fetch_array( $result )) {echo "<option>$row['rank']</option>";}echo "</select><br>";}...?>[/code]So that creates an array of your inputs automatically...to teh insert statement....[code]<?phpif($dbsubmit) {mysql_connect("*", "*", "*") or die(mysql_error());mysql_select_db("*") or die(mysql_error());$no_entered = coount($_POST['rsid']);$tempstr = NULL:for ($i = 0; $i < $no_entered; $i++) { if ($i > 0) { $temp .= ", "; } $temp . = "('' , '$_POST['rsdi'][$i]', '$_POST['msndi'][$i]', '$_POST['rank'][$i]')";}$qry = "INSERT INTO MSN(ID, rsid, msnid, rank) VALUES " . $qry . ";$qry = mysql_query($qry)or die(mysql_error());echo "CHANGE THIS MESSAGE MAYBE SHOW THE NUMBER OF AFFECTED ROWS!";}?>[/code]something liek that will do ya. Quote Link to comment Share on other sites More sharing options...
Eugene Posted April 13, 2006 Author Share Posted April 13, 2006 A bunch of parse errors appear after I use that... Quote Link to comment Share on other sites More sharing options...
Eugene Posted April 13, 2006 Author Share Posted April 13, 2006 [a href=\"http://imageshack.us\" target=\"_blank\"][img src=\"http://img464.imageshack.us/img464/6687/help2jn.png\" border=\"0\" alt=\"IPB Image\" /][/a]That what appears in the database if I use Arrays. Can anyone help please! 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.