[英]PHP update SQL table to a logged in user
I'm trying to get a logged in user's input from a text box to be inserted into a column on their row. 我正在尝试从文本框中获取登录用户的输入,以将其插入到其行的列中。 Right now I am able to insert data into my database but it comes up as a new record.
现在,我可以将数据插入数据库中,但它会作为新记录出现。 I'm struggling to find a way to point it to the specific logged in user so it adds to that row rather than creating a new record.
我正在努力寻找一种方法,将其指向特定的登录用户,以便将其添加到该行中,而不是创建新记录。
form code in payment.php
: payment.php
表单代码:
<form class="test" action="payment.php" method="post" autocomplete="off">
<input type="text" required class="text" name='bitaddress' placeholder="Public Key...">
<input class="wow shake" data-wow-delay="0.3s" type="submit" value="Accept" name="accept" />
</form>
PHP code in payment.php
: payment.php
PHP代码:
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST['accept'])) {
require 'paymentProccess.php';
}
}
?>
lastly my code inside paymentProccess.php
: 最后,我在
paymentProccess.php
代码:
<?php
require 'db.php';
$bitaddress = $mysqli->escape_string($_POST['bitaddress']);
$user_name = $_SESSION['user_name'];
$email = $_SESSION['email'];
$active = $_SESSION['active'];
$paid = $_SESSION['paid'];
$sql = "INSERT INTO users (bitaddress) " . "VALUES ('$bitaddress')";
if ( $mysqli->query($sql) ){
}
?>
Thanks for the comments of help. 感谢您对帮助的评论。 After 3-4 hours I ended up working it out if anyone else has this issue.
3-4小时后,如果其他人遇到此问题,我最终进行了解决。
firstly I got the "id" for the user which is my primary key. 首先,我获得了用户的“ id”,这是我的主键。
$id = $_SESSION['id'];
then on my paymentProccess.php
page I used this: 然后在我的
paymentProccess.php
页面上,我使用了以下方法:
<?php
require 'db.php';
$bitaddress = $mysqli->escape_string($_POST['bitaddress']);
$user_name = $_SESSION['user_name'];
$email = $_SESSION['email'];
$active = $_SESSION['active'];
$paid = $_SESSION['paid'];
$id = $_SESSION['id'];
$sql = "UPDATE users SET bitaddress = '$bitaddress' WHERE id = '$id'";
if ( $mysqli->query($sql) ){
}
?>
note: I'm not sure if this is the most efficient way of doing it. 注意:我不确定这是否是最有效的方法。 It could have security flaws etc. But when i refreshed phpMyAdmin I had a massive amount of stress relieved.
它可能存在安全漏洞等。但是当我刷新phpMyAdmin时,我的压力减轻了。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.