Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- The Error Messages: http://prntscr.com/awsb5m
- The Code:
- <html>
- <head>
- <title>Add User</title>
- </head>
- <body>
- <?php
- if(isset($_POST['submit'])){
- $data_missing = array();
- if(empty($_POST['username'])){
- // Adds name to array
- $data_missing[] = 'Username';
- } else {
- // Trim white space from the name and store the name
- $username = trim($_POST['username']);
- }
- if(empty($_POST['password'])){
- // Adds name to array
- $data_missing[] = 'Password';
- } else{
- // Trim white space from the name and store the name
- $password = trim($_POST['password']);
- }
- if(empty($_POST['email'])){
- // Adds name to array
- $data_missing[] = 'Email';
- } else {
- // Trim white space from the name and store the name
- $email = trim($_POST['email']);
- }
- if(empty($data_missing)){
- require_once('../mysqli_connect.php');
- $query = "INSERT INTO user_details (username, password, email) VALUES (?, ?)";
- $stmt = mysqli_prepare($dbc, $query);
- mysqli_stmt_bind_param($stmt, "ss", $username, $password, $email);
- mysqli_stmt_execute($stmt);
- $affected_rows = mysqli_stmt_affected_rows($stmt);
- if($affected_rows == 1){
- echo 'User Entered';
- mysqli_stmt_close($stmt);
- mysqli_close($dbc);
- } else {
- echo 'Error Occurred<br />';
- echo mysqli_error();
- mysqli_stmt_close($stmt);
- mysqli_close($dbc);
- }
- } else {
- echo 'You need to enter the following data<br />';
- foreach($data_missing as $missing){
- echo "$missing<br />";
- }
- }
- }
- ?>
- <form action="http://localhost/useradded.php" method="post">
- <b>Add a New User</b>
- <p>Username:
- <input type="text" name="username" size="30" value="" />
- </p>
- <p>Password:
- <input type="password" name="password" size="30" value="" />
- </p>
- <p>Email:
- <input type="text" name="email" size="30" value="" />
- </p>
- <p>
- <input type="submit" name="submit" value="Send" />
- </p>
- </form>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement