ユーザーがフィードバックを書き込んで、ページ全体を更新せずにphp mysqliを使用してデータベースに保存できるフィードバックフォームを作成しています。成功メッセージが表示されましたが、データが入力されていないので、誰か助けてもらえますか? 私は昨日同じ質問をしましたphp mysqli 挿入および更新クエリ
feedback_form.php
<?php
session_start();
$login = ($_SESSION['login']);
$userid = ($_SESSION['user_id']);
$login_user = ($_SESSION['username']);
$fname = ($_SESSION['first_name']);
$lname = ($_SESSION['last_name']);
$sessionaddres =($_SESSION['address']);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>feedback page</title>
<script type = "text/javascript" src = "http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<link href="style/stylesheet.css"rel="stylesheet" type="text/css"/>
<script type = "text/javascript">
$(function(){
$('#submit').click(function(){
$('#container').append('<img src = "images/loading.gif" alt="Currently loading" id = "loading" />');
var comments = $('#comments').val();
$.ajax({
url: 'feedback_process.php',
type: 'POST',
data: {"comments": comments},
success: function(result){
$('#response').remove();
$('#container').append('<p id = "response">' + result + '</p>');
$('#loading').fadeOut(500, function(){
$(this).remove();
});
}
});
return false;
});
});
</script>
</head>
<?php require_once('header.php'); ?>
<body>
<form action = "feedback_form.php" method = "post">
<div id = "container">
<h2><?php echo $login_user ?></h2>
<label for = "comments">Comments</label>
<textarea rows = "5"cols = "35" name = "comments" id = "comments"></textarea>
<br />
</div>
</form>
<input type = "submit" name = "submit" id = "submit" value = "send feedBack" />
</body>
</html>
feedback_process.php
<?php
session_start();
$login = ($_SESSION['login']);
$userid = ($_SESSION['user_id']);
$login_user = ($_SESSION['username']);
$fname = ($_SESSION['first_name']);
$lname = ($_SESSION['last_name']);
$sessionaddres =($_SESSION['address']);
$conn = new mysqli('localhost', 'root', 'root', 'lam_el_chamel_db');
echo"<pre>";
print_r($_POST);
echo"</pre>";
if(isset($_POST['comments'])){
$comments = $_POST['comments'];
$query = "INSERT into feedback (feedback_text, user_name,) VALUES(?,?)";
$stmt = $conn->stmt_init();
if($stmt->prepare($query))
{
$stmt->bind_param('ss', $comments, $login_user);
$stmt->execute();
}
$query2 = "UPDATE feedback SET feedback_text = ?, user_name = ? WHERE user_name = ? ";
$stmt = $conn->stmt_init();
if($stmt->prepare($query2))
{
$stmt->bind_param('sss', $comments, $login_user, $login_user);
$stmt->execute();
}
if($stmt){
echo "thank you .we will be in touch soon <br />";
}
else{
echo "there was an error. try again later.";
}
}
else
echo"it is a big error";
?>