Good day all ,
I am in the processes of creating a add buyer page for an auction site. However , the rows are not updating when i add a new buyer. Below is the code i have written .
This is the add buyer form page :
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<?php
echo "<img id='logo' src='auction.png'/>";
echo "<br>";
echo "<form class='add_buyer_form' action='check_buyer.php' method='POST'>";
if (isset($_GET["buyer"]))
{
if($_GET["buyer"] == "successful")
{
echo"<h4>Successfully added user!</h4>";
}
else if ($_GET["buyer"] == "duplicate")
echo"<h4? BUyer already exists. Please enter another username and password<h4>";
}
else
{
echo "<h4>Please Add the buyers username and password</h4>";
}
echo "<label class='label' for='username'>Username:</label>";
echo "<input class='text' type='text' name='username' placeholder='username'>";
echo "<br>";
echo "<label class='label' for='password'>Password:</label>";
echo "<input class='password' type='password' name='password' placeholder='Password'>";
echo "<input class='submit' type='submit' value='Add Buyer'>";
echo"</form>";
?>
</body>
</html>
This is the check buyer form page :
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<?php
if (!empty($POST["username"]) && !empty($_POST["password"]))
{
$DBHOST = "localhost";
$DBUSER = "tim";
$DBPWD = "nineteen1985";
$DBNAME = "customs_auction";
$conn = new mysqli($DBHOST, $DBUSER, $DBPWD, $DBNAME);
if ($conn->connect_error)
{
die("connection failed:" .$conn->connect_error);
}
$username = $_POST["username"];
$password = $_POST["password"];
$hashed = password_hash($password, PASSWORD_DEFAULT);
$statement = "SELECT * FROM buyer WHERE username=?";
$stmt = $conn->prepare($statement);
$stmt->bind_param("s", $username);
$stmt->execute;
$result = $stmt->get_result();
if ($result->num_rows>=1)
{
$value = "duplicate";
header("Location: add_buyer.php?buyer=$value");
}
else
{
$statement = "INSERT INTO buyer(username,password) VALUES(?, ?)";
$stmt = $conn->prepare($statement);
$stmt->bind_param("ss", $username, $hashed);
$stmt->execute;
$value = "successful";
header("Location: add_buyer.php?buyer=$value");
}
$conn->close();
}
else
{
header("Location: add_buyer.php");
}
?>
</body>
</html>