Advertisement
Guest User

Untitled

a guest
Mar 29th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title>PHP Form</title>
  5. </head>
  6. <body>
  7. <form action="" method="post" name="form1">
  8. Name: <input type="text" name="username" placeholder="Your name">
  9. Password: <input type="password" name="password" placeholder="Your password">
  10. Email: <input type="email" name="email" placeholder="Your email">
  11. <input type="submit" name="submit" value="Submit!">
  12. </form>
  13. <?php
  14. if ($_SERVER['REQUEST_METHOD'] == 'POST')
  15.     $dbName="myTest";
  16.     $user="root";
  17.     $pass="";
  18.     $host="localhost";
  19.     $link = mysql_connect($host, $user, $pass);
  20.     if(!$link){
  21.         die('Could not connect: ' . mysql_error());
  22.     }
  23.     $dbselected = mysql_select_db($dbName, $link);
  24.     if(!dbselected){
  25.         die('Can\'t use ' . $dbName . ":" . mysql_error());
  26.     } else{
  27.         echo "Connected successfully";
  28.     }
  29.     $username=$_POST['username'];
  30.     $password=$_POST['password'];
  31.     $email=$_POST['email'];
  32.     /**
  33.     ** WARNING **
  34.     **
  35.     **THIS INSERT STATEMENT IS OPEN TO SQL INJECTION ATTACK
  36.     **
  37.     **/
  38.     $sql = "INSERT INTO myTable (username, password, email) VALUES ('$username', '$password', '$email')";
  39.     if(!mysql_query($sql)){
  40.         die("Error: " . mysql_error());
  41.     }
  42.     echo "Insert worked...";
  43. }
  44. ?>
  45. </body>
  46. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement