[英]No error when inserting values from drop down but won't insert
I have a dropdown loop and when I try to select a number from the drop down it echoes out. 我有一个下拉循环,当我尝试从下拉列表中选择一个数字时,它会回响。 but when i insert it, it won't execute or won't display in the database rather.
但是当我插入它时,它将不会执行或不会显示在数据库中。 but when I change the $_POST value to a static number, it inserts and displays.
但是当我将$ _POST值更改为静态数字时,它会插入并显示。 like $x=$_POST['category'];
比如$ x = $ _ POST ['category']; it doesn't insert, but $x=3;
它不插入,但$ x = 3; it inserts in the database Here is what I got :
它插入数据库这是我得到的:
/*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();
It should be because you have defined the DB field as INT. 应该是因为您已将DB字段定义为INT。 Try below code :
试试以下代码:
$x = (int)$POST['category'];
before you write $adviser=$_SESSION['user_id'];
在你写
$adviser=$_SESSION['user_id'];
you should use session_start(); 你应该使用session_start();
if not work , manually execute insert query on your database and check error 如果不起作用,请在数据库上手动执行插入查询并检查错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.