Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //1. Database conecction
- $dbhost = "localhost";
- $dbuser = "www95mca_cat";
- $dbpass = "Fireheart";
- $dbname = "www95mca_dragon";
- $connection = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
- //Test is connection works
- if(mysqli_connect_errno()){
- die("connection failed" . mysqli_connect_error() . "(". mysqli_connect_errno() .")");
- }
- ?>
- <?php
- //2. Perform query
- // Hard coded to test
- $first = "dragon";
- $last = "summer";
- $username = "Darkbreeze";
- $password = "Firestorm";
- $query = "INSERT INTO meow (first, last, username, password)
- VALUES ('$first}', '{$last}', '{$username}', '{$password}')";
- //Most of the time these come from a form with post method
- $result = mysqli_query($connection, $query);
- if($result){
- echo "success";
- } else {
- die("failed");
- }
- ?>
- <?php
- //3.Use returned data
- while($row = mysqli_fetch_row($result)){
- //get the first row and assign to the variable, loop increment
- var_dump($row);
- //output from each row
- echo "<hr />";
- //horizontal line tag
- }
- ?>
- <?php
- //4. Release the data
- mysqli_free_result($result);
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>database</title>
- </head>
- <body>
- </body>
- </html>
- <?php
- //5. Close the connection
- mysqli_close($connection);
- ?>
Add Comment
Please, Sign In to add comment