Jump to content

SQL Post Problem


steveb1471

Recommended Posts

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.