hi,i am facing problem about when i choose more than 2 selected data from the multiple drop-down list ,there onli have 1 data successfully insert into database.

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO c_register (id, c_code, c_name, p_name, inctructor_name, c_category, c_group, c_credit_h, c_total_learning_h, c_pre_requirement, c_synopsis, c_reference, c_examination_mark, c_coursework_mark) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['id'], "int"),
                       GetSQLValueString($_POST['c_code'], "text"),
                       GetSQLValueString($_POST['c_name'], "text"),
                       GetSQLValueString($_POST['p_name'], "text"),
<form action="<?php echo $editFormAction; ?>" method="post" id="form1">
      <table>
        <tr valign="baseline">
          <td align="right">Id:</td>
          <td><input type="text" name="id" value="" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <td align="right">C_code:</td>
          <td><input type="text" name="c_code" value="" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <td align="right">C_name:</td>
          <td><input type="text" name="c_name" value="" size="32" /></td>
        </tr>
        <tr valign="baseline">
          <td align="right">P_name:</td>
          <td><select name="p_name"  multiple="multiple" size="4">
            <option value="" ></option>
            <?php
do {  
?>
            <option value="<?php echo $row_Recordset2['p_name']?>"><?php echo $row_Recordset2['p_name']?></option>

have you try this already?

<select name="p_name[]" multiple="multiple" size="4">
<option value="" ></option>
<option value="1" >1</option>
.
.
.
//etc
$p_name= $_POST['p_name'];
$pname='';
if( is_array($p_name)){
 while (list ($key, $val) = each ($p_name)) {
 $pname .= $val;
 }
}

this is what i try~ but still cannot ~~

<form name="test" method="post" action="">
  <label>
    <select name="p_name[]" multiple="multiple" size="4" id="p_name">
      <option value="1">ee</option>
      <option value="2">rrrrr</option>
      <option value="3">rrrrrrrr</option>
      <option value="4">ffffffff</option>
  </select>
  </label>
  <label>
    <input type="submit" name="Submit" id="Submit" value="Submit">
  </label> 
</form>
     
<?php
require_once ('../../../Connections/admin_db.php'); 

mysql_select_db("admin_db");

if ((isset($_POST["Submit"])) && ($_POST["Submit"] == "Submit")) {
	
    $p_name= $_POST['p_name'];
$pname='';
if( is_array($p_name)){
 while (list ($key, $val) = each ($p_name)) {
 $pname .= $val;

 $q = "INSERT INTO c_p(p_name)VALUES ('$p_name') " ;
				 
 mysql_query($q) or die(mysql_error()) ;

}

 ?>
//here's a working sample, save this as test.php to see the result
<?php
if ((isset($_POST["Submit"])) && ($_POST["Submit"] == "Submit")) {
	$p_name= $_POST['p_name'];
	for($i=0; $i<count($p_name); $i++){
		echo $p_name[$i].'<br/>';
		//mysql_query("INSERT INTO c_p(p_name)VALUES ('$p_name[$i]') or die(mysql_error()) ;
		}
	}
?>
<form name="test" method="post" action="<? $_SERVER['PHP_SELF'] ?>">
  <label>
    <select name="p_name[]" multiple="multiple" size="4" id="p_name">
      <option value="1">ee</option>
      <option value="2">rrrrr</option>
      <option value="3">rrrrrrrr</option>
      <option value="4">ffffffff</option>
  </select>
  </label>
  <label>
    <input type="submit" name="Submit" id="Submit" value="Submit">
  </label> 
</form>

i have try it ~ but cannot work ~it showing Access forbidden!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.