Adding a User into database with PHP

To insert the record into database using PHP
$self = $_SERVER['PHP_SELF'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$username = $_POST['username'];
$password = $_POST['password'];
if((!$firstname) || (!$lastname) || (!$username) || (!$password)){
  $form ="Please enter in all the fields, to a new user details...";
  $form.="<form action=\"$self\" method=\"post\">";
  $form.="First Name: <input type=\"text\" name=\"firstname\" value=\"$firstname\"><br>";
  $form.="Last Name: <input type=\"text\" name=\"lastname\" value=\"$lastname\"><br>";
  $form.="Username: <input type=\"text\" name=\"username\" value=\"$username\"><br>";
  $form.="Password: <input type=\"text\" name=\"password\" value=\"$password\"><br>";
  $form.="<input type=\"submit\" value=\"Submit\">";
  $conn = @mysql_connect("localhost","root", "") or die("Could not connect to MySQL");
  $db = @mysql_select_db("my_database",$conn) or die("Could not select database");
  $sql = "INSERT INTO users (first_name,last_name,user_name,password)
         VALUES ('$firstname','$lastname','$username',password('$password'))";
  $result = @mysql_query($sql,$conn)or die("Could not execute query");
     echo("New user $username added");

Post to Twitter Post to Digg Post to Facebook Post to Google Buzz Send Gmail

Leave a Comment

Your email address will not be published. Required fields are marked *