Have tried the following but still in database record is not getting inserted , please help
Page Name : multipleselect
<body>
<form action="multipleselectlogic.php" method="post">
<select name="course[]" multiple="multiple">
<option value="math01">Math 001</option>
<option value="math02">Math 002</option>
<option value="math03">Math 003</option>
<option value="math04">Math 004</option>
<option value="math05">Math 005</option>
<option value="math06">Math 006</option>
<option value="math07">Math 007</option>
</select>
<input type="submit" value="Add" name="send" />
</form>
</body>
</html>
Page Name : multipleselectlogic
<body>
<?php
$con = mysqli_connect("156.62.38.214","abc","abc22#","checkarray");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$std_id = 20;
$course = $_POST['course'];
if($course)
{
foreach ($course as $c)
{
print_r($course);
echo $std_id;
$sql = mysqli_query($con, "INSERT INTO check(course,std_ID)
VALUES('mysqli_real_escape_string($con , $c)','$std_ID')");
if($con->query($sql)== TRUE)
{
echo " Insert Successfull";
}
else
{
echo "Error:" . $sql . "<br>" . $con->error;
}
}
}
?>
</body>
Database : checkarray
Table Name : check
ID - Primary Key , Auto_increment - Null ( No )
course - varchar(100) - Null ( Yes )
std_ID - int(11) - Null ( Yes )
collation : utf8_general_ci
Details
I am not getting any error ( echo "Error:" . $sql . "
" . $con->error; ) , but no record are inserted into database
Aucun commentaire:
Enregistrer un commentaire