ユーザー名の表示に問題があります。私の SQL は、コメントを追加したユーザー名を記録できません....現在のログイン ユーザー名のみを表示します...どうすればよいですか? お客様がコメントを挿入する際に、再度名前を入力してほしくありません....
<?php
if ($_POST) {
$name = mysqli_escape_string($conn, $_POST['name']);
$supplier = mysqli_escape_string($conn, $_POST['supplier']);
$description = mysqli_escape_string($conn, $_POST['description']);
$remark = mysqli_escape_string($conn, $_POST['remark']);
$price = mysqli_escape_string($conn, $_POST['price']);
$image = mysqli_escape_string($conn, $_POST['image']);
$createdate = mysqli_escape_string($conn, $_POST['createdate']);
$author = ( isset( $_SESSION["username"] ) ? $_SESSION["username"] : "" );
$result = mysqli_query($conn, "INSERT INTO products (name, supplier, description, remark, price, image, createdate,author) VALUES('$name', '$supplier', '$description', '$remark', '$price', '$image', '$createdate','$author')");
if (!$result) {
exit(mysqli_error($conn));
}
redirect('comment.php'); } else { ?>
<?php } ?>
サブミット.PHP
<?php
include("common.php");
logincheck();
$action = (isset($_GET["action"]) ? $_GET["action"] : "");
$link = mysql_connect("localhost", "XX", "XX");
mysql_select_db("XX");
$name = $_POST["name"];
$supplier = $_POST["supplier"];
$description = $_POST["description"];
$remark = $_POST["remark"];
$price = $_POST["price"];
$image = '';
if ( isset( $_FILES['image']['name'] ) && trim( $_FILES['image']['name'] ) != "" )
{
$uploaddir = "Products/";
$image = $uploaddir . basename($_FILES['image']['name']);
if ( ! move_uploaded_file( $_FILES['image']['tmp_name'], $image ) ) {
die('Image cannot be uploaded');
}
}
switch($action) {
case "insert":
$sql = "insert into products (name, supplier, description, remark, price, image, createdate) values ('$name', '$supplier', '$description', '$remark', '$price', '$image', NOW())";
mysql_query($sql, $link);
break;
case "save":
$id = $_POST["id"];
$image2 = $_POST["image2"];
if ($image == '')
$image = $image2;
$sql = "update products set name='$name', supplier='$supplier', description='$description', remark='$remark', price='$price', image='$image' where id='$id'";
mysql_query($sql, $link);
break;
case "delete":
$id = $_GET["id"];
$sql = "delete from products where id=$id";
mysql_query($sql, $link);
break;
}
Header( "Location: comment.php" );
?>