+ 2

how to insert username and password in data base

9th Sep 2017, 4:17 AM
Daulat Patel
Daulat Patel - avatar
2 Answers
+ 5
Connect your database with front end. Create HTML input fields and run a sql query to insert data into a database table.
9th Sep 2017, 4:36 AM
Sachin Artani
Sachin Artani - avatar
+ 4
You need PHP and Mysql. Below is the Php code that performs create new database data of username and email upon form submit. <!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8"> <title>Add Email Form</title> </head> <body> <form method="post"> <p> <label for="name">Username:</label> <input type="text" name="name" id="name"> </p> <p> <label for="email">Email Address:</label> <input type="text" name="email" id="email"> </p> <input type="submit" value="Send"> </form> </body> </html> <?php if(!empty($_POST['name']) && !empty($_POST['email'])) { $link = mysqli_connect("localhost", "root", "password", "demo"); // Check connection demo database if($link === false){ die("ERROR: Could not connect. " . mysqli_connect_error()); } // Escape user inputs for security $name = mysqli_real_escape_string($link, $_POST['name']); $email = mysqli_real_escape_string($link, $_POST['email']); // attempt insert query execution $sql = "INSERT INTO persons (name, email) VALUES ('$name', '$email')"; if(mysqli_query($link, $sql)){ echo "Records added successfully."; } else{ echo "ERROR: Could not able to execute $sql. " . mysqli_error($link); } // close connection mysqli_close($link); } ?> https://code.sololearn.com/w8uC90WWcV3D/?ref=app
9th Sep 2017, 6:02 AM
CalviŐČ
CalviŐČ - avatar