Hey everyone, I'm working on a small webshop project. I have register and login form which are working fine and are storing data into table users. Now, I have another table: orders, in which I want to transfer data from logged user when he makes order.
users data: id, username, email, password, address, city, country
orders data: id, username, email, address, city, country, item, quantity, price, total_price (where i want firt 6 data to be the same as user which ordered something from the shop)
this is the php code in index.php regarding storing the data in orders table
There is no error codes, it just does nothing when clicked on purchase_btn
any help would be lovely, thanks :)
users data: id, username, email, password, address, city, country
orders data: id, username, email, address, city, country, item, quantity, price, total_price (where i want firt 6 data to be the same as user which ordered something from the shop)
this is the php code in index.php regarding storing the data in orders table
Code:
<?php
require_once('connect.php');
$username2 = $_SESSION['username'];
$email = $_SESSION['email'];
$address = $_SESSION['address'];
$city = $_SESSION['city'];
$country = $_SESSION['country'];
if (isset($_POST['purchase_btn']))
{
$sql = "SELECT * FROM users WHERE username='$username2'";
$result = mysqli_query($conn, $sql);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_assoc($result))
{
$id = $row["id"];
$username2 = $row["username"];
$email = $row["email"];
$address = $row["address"];
$city = $row["city"];
$country = $row["country"];
}
$item = $_POST['item'];
$quantity = $_POST['quantity'];
$price = $_POST['price'];
$total_price = $_POST['total_price'];
$sql = "INSERT INTO orders (username, email, address, city, country, item, quantity,
price, total_price) VALUES ('$username2', '$email', '$address', '$city',
'$country', $item, $quantity, $price, $total_price);";
mysqli_query($conn, $sql);
}
}
?>
any help would be lovely, thanks :)
Comment