phpMyAdmin- Auto-Increments but doesn't show other data once I submit data


#1

How do I make it so that I can add new lines in between the following code? I have tried and can’t make it work. I am new to phphelp. Thanks!!

I am trying to submit data from a “signup” form into a database. Once I submit the data, the ID auto-increments but the other data such as first and last name, email, username, and password is not uploaded and does not show in my table ‘users’. Please tell me whats wrong. Here is the code:

START FILE***signupForm1.dbh.inc.php

<?php

$dbServername="localhost";
$dbUsername="root";
$dbPassword="";
$dbName="database1";

$conn=mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);

***END FILE***

***START FILE***index.signupForm1.php***

<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>

<form action="includes/signupForm1.inc.php" method="POST">
<input type="text" name="first" placeholder="Firstname">
<br>
<input type="text" name="last" placeholder="Lastname">
<br>
<input type="text" name="email" placeholder="E-mail">
<br>
<input type="text" name="uid" placeholder="Username">
<br>
<input type="password" name="pwd" placeholder="Password">
<br>
<button type="submit" name="submit">Sign Up</button>
</form>

</body>
</html>

END FILE

START FILE***index2.signupForm1.php

<!DOCTYPE html>
<html>
<head>
	<title></title>
</head>
<body>

<?php

include_once 'includes/signupForm1.dbh.inc.php';

$data="Admin";
//Create a template
$sql='SELECT * FROM users WHERE user_uid=?;';
//Create a prepared statement
$stmt=mysqli_stmt_init($conn);
//Prepare the prepared statement
if (!mysqli_stmt_prepare($stmt, $sql)) {
	echo 'SQL statement failed';
} else {
//Bind parameters to the placeholder
mysqli_stmt_bind_param($stmt, 's', $data);
//Run  parameters inside database
mysqli_stmt_execute($stmt);
$result=mysqli_stmt_get_result($stmt);

while ($row=mysqli_fetch_assoc($result)) {
	echo $row[‘user_uid’] . '<br>';
}
}
?>

</body>
</html>

END FILE

START FILE***signupForm1.inc.php

<?php
include_once 'signupForm1.dbh.inc.php';

$first=mysqli_real_escape_string($conn, $_POST[‘first’]);
$last=mysqli_real_escape_string($conn, $_POST[‘last’]);
$email=mysqli_real_escape_string($conn, $_POST[‘email’]);
$uid=mysqli_real_escape_string($conn, $_POST[‘uid’]);
$pwd=mysqli_real_escape_string($conn, $_POST[‘pwd’]);

$sql="INSERT INTO users (user_first, user_last, user_email, user_uid, user_pwd) VALUES (?, ?, ?, ?, ?);";
$stmt=mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo 'SQL error';
} else {
	mysqli_stmt_bind_param($stmt, 'sssss', $first, $last, $email, $uid, $pwd);
	mysqli_stmt_execute($stmt);
}

header('Location: ../index.SignupForm1.php?signup=success');

END FILE

I am using Notepad++ for this task.
Thanks for viewing and please help!


#2

Next time please use the correct tags so we can read your code! It is just all run-on text now.
You can tag it and use the preformatted-text button to make it readable.

So, how have you tested this so far? First, you showed us just the PHP code. You should check your HTML form and make sure the names of the fields are correct. Next, have your code display the posted data so you can see if the form is posting to your PHP code. Lastly, you did not validate your inputs. Meaning you did not check if the fields were entered or not. You just blindly save them. The page might not be posting them.

Look over your code and show us some of the HTML, too. For a test, I usually create one file with all the parts needed and displays at various points to make sure everything it working. I did not see where you checked if the form was posted or not. It appears that this code just runs without checking for anything at all.

Post your code again using the correct tags and we will help you get it working.