gpt4 book ai didi

php - 我正在尝试插入 SQL 查询,但没有在数据库中插入任何内容

转载 作者:行者123 更新时间:2023-11-29 22:59:18 25 4
gpt4 key购买 nike

我正在尝试使用 PHP 编写简单的脚本并插入一些数据,但没有任何反应!我知道我错过了一些东西,但它是什么?

这是我的代码:

<?php
$host= "localhost";
$user="root";
$pass="freedoom19";
$db="dddd";

$con = mysqli_connect($host,$user,$pass,$db) or mysql_error();

//====== Get Variable======= //
$name = $_POST['name'];
$email=$_POST['email'];
$rate=$_POST['select_style'];
$content=$_POST['content'];

$insert="insert into reviews (name,email,rate,content) values ('$name','$email','$rate','$content')";

//====== Get Variable======= //
if($_POST['submit-comment']) {
if($name && $email && $content == true) {

mysqli_query($con,$insert);
$success = "<span class='success_testmonial'>Thank You! .. Your Raiting Has Been Submitted And We Will Post It As Soon We Verify It !</span>";
}
else {

$error = "<span class='error_testmonial'>Error : one or some fields has left empty .. Please fill all field and try again.</span>";

}
}
mysqli_close($con);
?>

这就是形式和“ Action ”..

                        <form method="post" action="" id="form-contact" class="clearfix">
<div id="form-left">
<label for="text-name">Name *</label><br />
<input type="text" name="name" class="input" id="text-name" /><br />
<label for="text-email">From *</label><br />
<input type="text" name="email" class="input" id="text-email" /><br />
<label for="text-phone">Rate us *</label><br />
<div class="select-style">
<select>
<option value="5.0">5.0</option>
<option value="4.5">4.5</option>
<option value="4.0">4.0</option>
<option value="3.5">3.5</option>
<option value="3.0">3.0</option>
<option value="2.5">2.5</option>
<option value="2.0">2.0</option>
<option value="2.0">2.0</option>
<option value="1.5">1.5</option>
<option value="1.0">1.0</option>
</select>
</div>
</div>
<div id="form-right">
<label for="text-comment">Review <span></span></label><br />
<textarea name="content" cols="10" rows="20" class="input textarea" id="text-comment"></textarea><br />
<input type="submit" name="submit-comment" class="button" value="Rate Us" />
</div>
<p id="text-contact">
<br><br><font color="#980303">Please Note *</font> Thate Your Reviews Will Not Published Untill We Check it and sure that the review don't contain Bad words or bad language, and be sure that we will publish all reviews and we accept criticism!
</form>

那么我错过了什么?

最佳答案

检查此工作代码。此外,您还没有将 Drop down 的元素名称设置为 select_style。它也因此引发错误。

PHP 代码

if(isset($_POST['submit-comment']) && $_POST['submit-comment']!='')  {

$host= "localhost";
$user="root";
$pass="";
$db="test";

$con = mysqli_connect($host,$user,$pass,$db) or mysql_error();

//====== Get Variable======= //
$name = mysqli_real_escape_string($con,$_POST['name']);
$email = mysqli_real_escape_string($con,$_POST['email']);
$rate = mysqli_real_escape_string($con,$_POST['select_style']);
$content = mysqli_real_escape_string($con,$_POST['content']);

$insert="insert into reviews (name,email,rate,content) values ('$name','$email','$rate','$content')";

if($name && $email && $content == true) {

mysqli_query($con,$insert);
$success = "<span class='success_testmonial'>Thank You! .. Your Raiting Has Been Submitted And We Will Post It As Soon We Verify It !</span>";
echo $success;
}
else {

$error = "<span class='error_testmonial'>Error : one or some fields has left empty .. Please fill all field and try again.</span>";
echo $error;

}

mysqli_close($con);
}

HTML

<form method="post" action="" id="form-contact" class="clearfix">
<div id="form-left">
<label for="text-name">Name *</label><br />
<input type="text" name="name" class="input" id="text-name" /><br />
<label for="text-email">From *</label><br />
<input type="text" name="email" class="input" id="text-email" /><br />
<label for="text-phone">Rate us *</label><br />
<div class="select-style">
<select name="select_style">
<option value="5.0">5.0</option>
<option value="4.5">4.5</option>
<option value="4.0">4.0</option>
<option value="3.5">3.5</option>
<option value="3.0">3.0</option>
<option value="2.5">2.5</option>
<option value="2.0">2.0</option>
<option value="2.0">2.0</option>
<option value="1.5">1.5</option>
<option value="1.0">1.0</option>
</select>
</div>
</div>
<div id="form-right">
<label for="text-comment">Review <span></span></label><br />
<textarea name="content" cols="10" rows="20" class="input textarea" id="text-comment"></textarea><br />
<input type="submit" name="submit-comment" class="button" value="Rate Us" />
</div>
<p id="text-contact">
<br><br><font color="#980303">Please Note *</font> Thate Your Reviews Will Not Published Untill We Check it and sure that the review don't contain Bad words or bad language, and be sure that we will publish all reviews and we accept criticism!
</form>

关于php - 我正在尝试插入 SQL 查询,但没有在数据库中插入任何内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28579299/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com