oduth Posted January 13, 2012 Share Posted January 13, 2012 Hi, I have an HTML and a PHP script inserting data into DB. My problem is when i submit the form, one of the arrays cannot be posted to my PHP Script. The first SELECT-OPTION Values (mail_select[]) are being posted correctly, however the second SELECT-OPTION Values (OS[]) are not. It brings empty value at all. If i put OS[] SELECT TAG to first place, -i mean put it before mail_select[] SELECT TAG-, this time mail_select[] brings nothing. And OS[] is being posted correctly. What could the possible problems be? Here is the HTML: bla..bla.. <html> <form id="SK" action="post.php" method="POST"> <tr> <td> <?php $conn = getConn(); mysql_select_db(getDBName(),$conn); $query = "select MEMBERS,NAME from mail;"; $result = mysql_query($query,$conn); echo "<form>"; echo "<select name=\"mail_select[]\" id=\"mail_select[]\" multiple=\"multiple\">"; while($row = mysql_fetch_array($result)) { $NAME = $row['NAME ']; $MEMBERS = $row['MEMBERS']; echo "<option value='$MEMBERS'>$NAME</option>"; } echo "</select></form>"; mysql_close($conn); ?> </td> </tr> <tr><td> <?php $conn = getConn(); mysql_select_db(getDBName(),$conn); $query = "select mark from olsystem;"; $result = mysql_query($query,$conn); echo "<form style=\"margin:20px 0\">"; echo "<select name=\"OS[]\" id=\"OS[]\" multiple=\"multiple\">"; while($row = mysql_fetch_array($result)) { $isim = $row['mark']; echo "<option value='$mark'>$mark</option>"; } echo "</select></form>"; mysql_close($conn); ?> </td> </tr> <tr height="40"><td width="170"><div class="rowElem"><input type="submit" value="GO!" /><input type="reset" value="Clear" /></div></td></tr> </form> </html> Here is my PHP script: <?php include("DB.php"); if(isset($_POST['OS'])){ $OS = implode(",",$_POST['OS']); $mail_select = implode(",",$_POST['mail_select']); register($OS,$mail_select); } function register($OS,$mail_select) { $conn = getConn(); mysql_select_db(getDBName(),$conn); $query ="insert into outage(OS,mail_select) values ('$OS','$mail_select')"; mysql_query($query,$conn); if(mysql_affected_rows()>0){ BLA BLA } else { } mysql_close($conn); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/254942-post-error-with-two-arrays-in-html-form/ Share on other sites More sharing options...
PFMaBiSmAd Posted January 13, 2012 Share Posted January 13, 2012 Nested <form></form> tags are invalid HTML. For any one form, you must have only one opening <form ... > tag and one closing </form> tag. Quote Link to comment https://forums.phpfreaks.com/topic/254942-post-error-with-two-arrays-in-html-form/#findComment-1307181 Share on other sites More sharing options...
oduth Posted January 13, 2012 Author Share Posted January 13, 2012 Thanks for the correction, i totally missed it. But, the problem still remains the same. The array is empty. bla..bla.. <html> <form id="SK" action="post.php" method="POST"> <tr> <td> <?php $conn = getConn(); mysql_select_db(getDBName(),$conn); $query = "select MEMBERS,NAME from mail;"; $result = mysql_query($query,$conn); echo "<select name=\"mail_select[]\" id=\"mail_select[]\" multiple=\"multiple\">"; while($row = mysql_fetch_array($result)) { $NAME = $row['NAME ']; $MEMBERS = $row['MEMBERS']; echo "<option value='$MEMBERS'>$NAME</option>"; } echo "</select>"; mysql_close($conn); ?> </td> </tr> <tr><td> <?php $conn = getConn(); mysql_select_db(getDBName(),$conn); $query = "select mark from olsystem;"; $result = mysql_query($query,$conn); echo "<select name=\"OS[]\" id=\"OS[]\" multiple=\"multiple\">"; while($row = mysql_fetch_array($result)) { $isim = $row['mark']; echo "<option value='$mark'>$mark</option>"; } echo "</select>"; mysql_close($conn); ?> </td> </tr> <tr height="40"><td width="170"><div class="rowElem"><input type="submit" value="GO!" /><input type="reset" value="Clear" /></div></td></tr> </form> </html> Quote Link to comment https://forums.phpfreaks.com/topic/254942-post-error-with-two-arrays-in-html-form/#findComment-1307183 Share on other sites More sharing options...
PFMaBiSmAd Posted January 13, 2012 Share Posted January 13, 2012 You would need to post your current code and you should never repeatedly open and close a database connection on one page. It takes a relatively long time to make each database connection. Just open the connection before your first query and either let php close it when the script on the page ends or close it yourself somewhere after the last query. Edit: Also, did you refresh the form in your browser so that the changes made to the HTML where updated in the browser? Quote Link to comment https://forums.phpfreaks.com/topic/254942-post-error-with-two-arrays-in-html-form/#findComment-1307184 Share on other sites More sharing options...
oduth Posted January 13, 2012 Author Share Posted January 13, 2012 Hello again, My mistake, i checked the wrong output page. It worked actually! Thanks so much for your help! Quote Link to comment https://forums.phpfreaks.com/topic/254942-post-error-with-two-arrays-in-html-form/#findComment-1307187 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.