我想处理我的评论,其中包含名称,电子邮件和消息到名为“评论”的数据库,但它不能。我确信phpmyadmin中的数据库名称与prosescomment.php中的相同。请帮忙
这是我的表格
<form action="prosescomment.php" method="POST" id="form" >
<div class="success_wrapper">
<div class="success">Contact form submitted!<br>
<strong>We will be in touch soon.</strong> </div>
</div>
<fieldset>
<input type="text" name="nama" placeholder="Name:">
<br class="clear">
<span class="error error-empty">*This is not a valid name.</span><span class="empty error-empty">*This field is required.</span>
<label class="email">
<input type="text" name="email" placeholder="E-mail:">
<br class="clear">
<span class="error error-empty">*This is not a valid email address.</span><span class="empty error-empty">*This field is required.</span> </label>
<label class="message">
<textarea type="text" name="message" placeholder="Message"></textarea>
<br class="clear">
<span class="error">*The message is too short.</span> <span class="empty">*This field is required.</span> </label>
<div class="clear"></div>
<div class="btns"><a data-type="submit" class="link1">Send</a>
<div class="clear"></div>
</div>
</fieldset>
</form>
这是我的prosescomment.php
<?php
include "connection.php";
$nama = $_POST['nama'];
$email = $_POST['email'];
$message = $_POST['message'];
$query = "INSERT INTO comment VALUES ('$nama', '$email', '$comment')";
$result = mysql_query($query);
if ($query) {
header("location:index.html");
}
else{
mysql_error();
}
?>
这是我的身份证明
#form {
padding-top: 6px;
}
#form input {
color:#39596e;
border: 1px solid #3c7f9f;
padding: 4px 12px 9px;
background-color: white;
float:left;
font: 13px/18px Arial, Helvetica, sans-serif;
box-sizing: border-box;
-moz-box-sizing: border-box; /*Firefox 1-3*/
-webkit-box-sizing: border-box; /* Safari */
}
#form textarea {
color:#39596e;
height: 170px;
overflow: auto;
background-color: white;
border: 1px solid #3c7f9f;
padding: 12px 12px 9px;
width: 100%;
position: relative;
resize:none;
box-sizing: border-box;
-moz-box-sizing: border-box; /*Firefox 1-3*/
-webkit-box-sizing: border-box; /* Safari */
float:left;
font: 13px/18px Arial, Helvetica, sans-serif;
margin: 0;
}
#form label {
position:relative;
display: block;
min-height: 51px;
width: 185px;
float: left;
}
.email {
padding-top: 10px;
}
#form .error, #form .empty {
color: #FF0000;
display: none;
font-size: 11px;
line-height:14px;
width:auto;
position: absolute;
z-index: 999;
right: 5px;
bottom: 4px;
float:left;
}
#form .message .error, #form .message .empty {
bottom: -16px;
}
#form .error-empty {
display:none;
float:left;
}
.btns {
position:relative;
padding-top: 20px;
text-align: center;
}
.btns a {
display: inline-block;
font-size: 19px;
line-height: 18px;
background-color: #f17c72;
border: 1px solid #b76058;
min-width: 107px;
padding: 5px 10px 6px;
color: #fff;
cursor: pointer;
}
.btns a:hover {
background-color: #c2e8f4;
border-color: #3c7f9f;
color: #39596e;
}
#form .message {
width: 100%;
}
#form .btns span {
display: inline-block;
width: 13px;
}
.message br {
height: 0;
line-height: 0;
}
#form .success {
display: none;
position: absolute;
width: 100%;
color:#39596e;
border: 1px solid #3c7f9f;
background-color: #c2e8f4;
text-align: center;
padding: 20px 10px;
z-index: 999;
box-sizing: border-box;
-moz-box-sizing: border-box; /*Firefox 1-3*/
-webkit-box-sizing: border-box; /* Safari */
}
.success_wrapper {
position: relative;
}
答案 0 :(得分:2)
似乎你有一个连接类左右......但是我建议你使用Prepared Statements&amp; PDO ......
此外,您的SQL可能是错误的,具体取决于您是否有主键(ID)。
以下是我建议您前往的路线:
<?php
include "connection.php";
$nama = htmlspecialchars(trim($_POST['nama'])); //PROTECT AGAINST SQL INJECTION
$email = htmlspecialchars(trim($_POST['email'])); //PROTECT AGAINST SQL INJECTION
$message = htmlspecialchars(trim($_POST['message'])); //PROTECT AGAINST SQL INJECTION
//NOTE: YOU DON'T HAVE THE VARIABLE $comment DEFINED: YOU MUST MEAN $message
$query = "INSERT INTO comment (name, email, message) VALUES ('$nama', '$email', '$message')";
/** I WOULD SUGGEST YOU USE PDO & PREPARED STATEMENTS LIKE SO*/
// $stmt = $dbh->prepare("INSERT INTO comment (name, email, comment) VALUES (:name, :email, :message)");
// $stmt->bindParam(':name', $nama);
// $stmt->bindParam(':email', $email);
// $stmt->bindParam(':message', $message);
$result = mysql_query($query);
// NOT if($query) BUT if($result) BECAUSE $query IS A STRING AND if($query) WILL ALWAYS RETURN TRUE...
if ($result) {
header("location:index.html");
}
else{
mysql_error();
}
?>
我希望这有点帮助...
答案 1 :(得分:1)
使用此代码查找您的html和prosescomment.php代码,它将运行
{{1}}
答案 2 :(得分:0)
请将代码行<a data-type="submit" class="link1">Send</a>
替换为<button class="link1" type="submit" >Send</button>
,然后尝试发布您的表单数据。