我已经制作了一个代码,可以将推荐信发布到数据库,但它无效。设置了所有变量,但在提交表单时,返回以下错误:“提交推荐时出现问题”。请帮我排除故障。感谢。
以下是代码:
<?php
$name=$_POST['name'];
$address=$_POST['address'];
$city=$_POST['city'];
$province=$_POST['province'];
$testimonial=$_POST['testimonial'];
// TIME
$postedon="3456787654";
// TIME
// SENTIMENT
$state="1";
// SENTIMENT
if ($state==true) {
// insert into database
require 'ddbconfig.php';
$insert=mysqli_query($con,"INSERT INTO d_tbltestimonias
(id,d_name,d_address,d_city,d_province,d_testimonial,postedon,state)
VALUES('$name', '$address', '$city', '$province',
'".addslashes($testimonial)."','$postedon', '$state')");
if ($insert==true) {
?>
<script type="text/javascript">
window.top.location.href='testimonials.php?posted';
</script>
<?php
}else{
echo "Problem while submitting testimonial";
}
// insert into database
}
?>
答案 0 :(得分:1)
您的代码中存在3个问题。
答案 1 :(得分:-1)
$sql = "INSERT INTO d_tbltestimonias
(d_name,d_address,d_city,d_province,d_testimonial,postedon,state)
VALUES('$name', '$address', '$city', '$province',
'".addslashes($testimonial)."','$postedon', '$state')";
$insert = $con->query($sql);
if ($insert === true) {
?>
<script type="text/javascript">
window.top.location.href='testimonials.php?posted';
</script>
<?php
}else{
echo "Problem while submitting testimonial";
}
}