Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- // Let's make a connection to a database
- // Database information
- $host = 'localhost'; // This means the database is on your computer
- $db_name = 'assignment'; // This is the table in your database
- $db_user = 'root'; // The username you log into for the database
- $db_pass = '1234'; // The respective password
- $db = new PDO('mysql:host='.$host.';dbname='.$db_name, $db_user, $db_pass);
- // Now we're connected. If we want to make sure we are, we can do:
- if ($db) {
- // Now we're definitely connected, so let's grab the information the user put in
- $username = $_POST['username'];
- $email = $_POST['email'];
- $password = $_POST['password'];
- // Now we have all the fields for the user, let's insert into the database
- $result = $db->query("INSERT INTO " . $db_name . " (username, email, password) VALUES ('".$username."', '".$email."', '".$password."');");
- // A few things to note:
- // The order is important (username, email, password) says the stuff in VALUES will be in that order
- // We can check if that was successful by:
- if ($result) {
- // Inserted correctly.
- } else {
- // Failed for some reason
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement