steveb1471 Posted August 13, 2020 Share Posted August 13, 2020 Hi I am new to development but really stumped by a problem i am having The below code gives no errors but does not populate the datebase with the infom Could anybody give me some pointers? <?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> <?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 (?, ?)"); $stmt = mysqli_stmt_init($conn); mysqli_stmt_bind_param($stmt,"ss",$name,$gender); mysqli_stmt_execute($stmt); header("Location: ../loginsystem/permnew1.php?success"); exit(); } ?> any help would be great Thanks Steve Quote Link to comment https://forums.phpfreaks.com/topic/311325-sql-post-problem/ Share on other sites More sharing options...
Barand Posted August 13, 2020 Share Posted August 13, 2020 You are missing the step to prepare the query before binding the parameters. I would strongly advise you use PDO rather than mysqli - much simpler. 2 Quote Link to comment https://forums.phpfreaks.com/topic/311325-sql-post-problem/#findComment-1580589 Share on other sites More sharing options...
Barand Posted August 13, 2020 Share Posted August 13, 2020 Also, if continuing to use mysqli, place this line before connecting to the db server mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); 1 Quote Link to comment https://forums.phpfreaks.com/topic/311325-sql-post-problem/#findComment-1580590 Share on other sites More sharing options...
steveb1471 Posted August 13, 2020 Author Share Posted August 13, 2020 completely missed it! ive added if (mysqli_stmt_prepare($stmt, $sql)) { Works perfectly thanks you so much!!!! Quote Link to comment https://forums.phpfreaks.com/topic/311325-sql-post-problem/#findComment-1580591 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.