[英]PHP SQL: I cant transfer data from 1 table to another table in database sql using UI button in php file
我正在尝试从一般联系人数据库表中添加个人联系人
用户将单击编辑按钮,然后他们将查看信息,然后再决定将其添加到个人联系人中。
我认为我的问题是我的 PHP 代码无法在我的 SQL INSERT INTO 语句中输入登录用户的 SESSION 名称。
这是 SQL 代码
if (isset($_POST['add'])) {
$user = $_POST['u_username'];
$contact_username = $_POST['contact_username'];
$savesql2 = "INSERT INTO personal_contacts (id,contact_username, u_username)
VALUES ( '$id','$contact_username', '$user')";
mysqli_query($db, $savesql2);
$_SESSION['message'] = "Contact saved";
header('location: index.php');
}
你的代码
$savesql2 = "INSERT INTO personal_contacts (id,contact_username, u_username)
VALUES ( '$id','$contact_username', '$user')";
假设有一个$id
、一个$contact_username
和一个$user
变量。 虽然$contact_username
和$user
确实存在,但$id
没有定义,这会导致麻烦。 如果$id
由您的表自动设置,那么您可以执行以下操作:
$savesql2 = "INSERT INTO personal_contacts (contact_username, u_username)
VALUES ( '$contact_username', '$user')";
如果没有,那么您还需要正确设置$id
。
重要的
您的代码容易受到 SQL 注入的影响,请阅读并重构您的代码以使其更安全。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.