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!