我有一个下拉循环,当我尝试从下拉列表中选择一个数字时,它会回显。但是当我插入它时,它将不会执行或不会显示在数据库中。但是当我将$ _POST值更改为静态数字时,它会插入并显示。 比如$ x = $ _ POST ['category'];它没有插入, 但是$ x = 3;它插入数据库中 这是我得到的:
/*The Drop Down*/
<select name="category">
<?php
$query=mysql_query("SELECT * FROM deliverable_category");
while($row=mysql_fetch_assoc($query)){ ?>
<option value="
<?php echo $row['deliverable_category_id'] ; ?> ">
<?php echo $row['deliverable'] ; ?>
</option>
<?php } ?>
</select>
/*The Query*/
$name=$_POST['title'];
$deliverable_desc=$_POST['deliverable_desc'];
$category_id=$_POST['category'];
$adviser=$_SESSION['user_id'];
$con=mysqli_connect("localhost","root","","obeo") ;
if(mysqli_connect_errno())
{
echo "<br/>Error connecting to database!";
exit();
}else
{
echo "<br/> ";
$sqlstmt="insert into deliverable(deliverable_title,deliverable_desc,adviser_id,deliverable_category_id) values(?,?,?,?)";
$stmt=$con->prepare ($sqlstmt);
$stmt->bind_param('ssss', $name,$deliverable_desc,$adviser,$category_id);
$stmt->execute();
答案 0 :(得分:1)
应该是因为您已将DB字段定义为INT。 请尝试以下代码:
$x = (int)$POST['category'];
答案 1 :(得分:0)
在你写$adviser=$_SESSION['user_id'];
之前,你应该使用session_start();
如果不起作用,请在数据库上手动执行插入查询并检查错误