如何在现有文本中添加新文本并在php + mysql中标识特定用户?

我想做一个表格,人们可以添加一些信息,这将合计到mysql表中的现有信息。就像说“日期”列一样,我有诸如05.05.2020、01.05.2020之类的信息。我想将11.05.2020添加到05.05.2020和01.05.2020附近。当我这样做时,它只会删除此信息并仅添加11.05.2020。但我希望它看起来像是05.05.2020,01.05.2020,11.05.2020。 我不知道该怎么办的第二件事是如何使用户表单输入与mysql中的数据匹配?让我们说它的形式说用户名:,日期:。用户名输入0001,而php使用该值并将其与mysql用户名列匹配。如果存在,它将日期添加到该特定的用户表。 这是我的代码: 的HTML:

 <html>
<head>
<title>
</title>
</head>
<body>
<form action="process.php">
<center>
<label for="accnum">Username</label><br>
<br>
<input type="text"  name="accnum" id="accnum"><br>
<br>
<label for="date">Date</label><br>
<input type="text"  name="date" id="date"><br>
</body>
</html>

和我的process.php

<?php

$link = mysqli_connect("localhost", "root", "123", "jbex");


if($link === false){
    die("w. " . mysqli_connect_error());
}

$accnum = mysqli_real_escape_string($link, $_REQUEST['accnum']);
$date = mysqli_real_escape_string($link, $_REQUEST['date']);


$sql = "UPDATE accounts (date) VALUES ( '$date' WHERE $accnum=?)";
if(mysqli_query($link, $sql)){
    echo "success.";
} else{
    echo "ERROR: " . mysqli_error($link);
}
 mysqli_close($link);
?>

在WHERE“ $ accnum =”附近放置什么,以便用户输入名为accnum的形式? 感谢您的阅读和帮助

评论
  • hipsum
    hipsum 回复

    Your syntax for the MySQL UPDATE query also appears to be incorrect. Consult the documentation on UPDATE query syntax. Your query should probably look closer to this.

    UPDATE accounts SET date = ? WHERE accnum = ?
    

    It looks like you're overwriting the value of the date column with the value provided by the user, where you say you're wanting to instead add the value to your existing data for that user.

    MySQL doesn't support list types, so you'd have to either store the dates using a different column type (e.g. varchar or text) or store the dates as rows in a separate table where each row in that table includes the primary key value for its respective user.

    You should also be using a prepared statement with a bound parameter for the values of the date value you want to add and the accnum value for the record you want to add that value to.