Jump to content

POST Error with two arrays in HTML form


oduth

Recommended Posts

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);
}
?>

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.