Burnsy Burnsy - 9 days ago 4
HTML Question

simple PHP signup form wont POST to MySQL Database

I'm very new to this, I made a php to test the connection with the database and it seems fine, but writing information to a table isn't working.

Heres the index.php (where the signup form is)

<!DOCTYPE html>
<meta charset="UTF-8">
<title>Title of the document</title>
<link rel="stylesheet" type="text/css" href="style.css">

<form action="signup.php" method="POST">
<input type="text" name="firstname" placeholder="Firstname"><br>
<input type="text" name="lastname" placeholder="Lastname"><br>
<input type="text" name="uid" placeholder="Username"><br>
<input type="text" name="pwd" placeholder="Password"><br>
<input type="submit">

Heres the signup.php (which is what i think might be broken)


include 'dbh.php';

$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$uid = $_POST['uid'];
$pwd = $_POST['pwd'];

$sql = "INSERT INTO useraccounts (firstname, lastname, uid, pwd)
VALUES ('$firstname', '$lastname', '$uid', '$pwd')";
$result = mysqli_query($conn, $sql);

header("Location: index.php");


and heres the dbh.php which connects to mysql


$conn = mysql_connect("hostname", "username", "password", "databasename");

if (!$conn) {
die("Connection failed: ".mysql_connect_error());


I'm sure there's already a load of questions like mine out there but I'm so new to this I'm finding it hard to learn from the answers I've come across


In your signup.php you use the following line (mysqli):

mysqli_query($conn, $sql);

However in your dbh.php you use (mysql):

mysql_connect("hostname", "username", "password", "databasename");



Other than that I can't see anything else what could be wrong. Your query seems correct and you declare your post data.

I suggest you try to look for error messages if the solution above doesnt provide anything.