Hi
I am learning as many of us are and i have come across something that has stumped me for a few days as was wondering if anyone could help.
the below code is throwing a error. I think its around the “insert into” section or where i bind paramiters but could be wrong. Could any help?
<?php
$dBServername = "localhost";
$dBUsername = "root";
$dBPassword = "";
$dBName = "loginsystemtut";
// Create connection
$conn = mysqli_connect($dBServername, $dBUsername, $dBPassword, $dBName);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
if(isset($_POST['insert']))
{
$name = $_POST['name'];
$gender = $_POST['gender'];
$sql = "INSERT INTO asdf (name,gender) values ($name, $Gender);";
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
// If there is an error we send the user back to the signup page.
header("Location: ../permnew1.php?error=sqlerror");
exit();
}
else {
mysqli_stmt_bind_param($stmt, "ss", $name, $gender);
mysqli_stmt_execute($stmt);
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo "New record created successfully";
}
else
{
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}
}
?>
Below is the code for the form
<?php
require “header.php”;
?><main> <div class="wrapper-main"> <section class="section-default"> <h1>Signup</h1> <?php if (isset($_GET["error"])) { if ($_GET["error"] == "emptyfields") { echo '<p class="signuperror">Please Fill In All Fields!</p>'; } } ?> <form class="form-add" action="" method="post"> <label>Name</label><br> <input type="text" name="name" placeholder="name"><br> <LABEL>Gender</LABEL><br> <select name="gender"> <option value="">--Select--</option> <option value="Male">Male</option> <option value="Female">Female</option> </select><br> <input type="submit" name="insert" value="Insert Data"> </form> </section> </div> </main>