Reputation: 165
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
:
<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
:
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST['accept'])) {
require 'paymentProccess.php';
}
}
?>
lastly my code inside 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) ){
}
?>
Upvotes: 1
Views: 690
Reputation: 165
Thanks for the comments of help. After 3-4 hours I ended up working it out if anyone else has this issue.
firstly I got the "id" for the user which is my primary key.
$id = $_SESSION['id'];
then on my paymentProccess.php
page I used this:
<?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.
Upvotes: 2