0

To run PHP you must be install LAMP server in your computer.
Install LAMP server ==> LAMP INSTALLATION


Create the following 4 files.
 
register_form.html


<!Doctype html>
<html>
<title>Registration form</title>
<h1>Registration  form</h1>
<form action="insert.php" method="post">
Name:<input type="text" name="name" /><br>
password:<input type="text" name="pas"/><br>
Address: <br>
<textarea name="addr" rows="6" cols="30"></textarea>
<input type="submit" value="submit" />
</form>
</html>


insert.php


<?php

mysql_connect("localhost","root","password") or die ("");
mysql_select_db("dbname");
$name =$_POST['name'];
$pas = $_POST['pas'];
$addr = $_POST['addr'];

$sql="insert into log values('$name','$pas','$addr') ";
mysql_query($sql);

header("location:register_form.html");
?>

main.html

<!Doctype html>
<html>
<title>Login form</title>
<h1>Login  form</h1>
<form action="check.php" method="post">
Name:<input type="text" name="name" /><br>
password:<input type="text" name="pas"/><br>
<input type="submit" value="submit" />
</form>
</html>


check.php

<?php

mysql_connect("localhost","root","password") or die ("");
mysql_select_db("dbname");
$name =$_POST['name'];
$pas = $_POST['pas'];

$sql = "select * from log where name='$name' and password='$pas' ";
$result=mysql_query($sql);
$count=mysql_num_rows($result);

if($count == 1)
 echo "Welcome ,logged in sucessfully";
else
 echo "<font color='red'>Wrong username 0r password</font>";
?>

Note: Chang dbname as your database name and password as your MySQL password.

After created these 4 files, open terminal and type

sudo nautilus

Now copy these 4 files and paste under /var/www/ folder and close it.

Open browser and type

http://localhost/register_form.html

Register your details and submit.

Again type

http://localhost/main.html

then enter username and password which is you registered, and press submit to check the database connectivity. Enjoy!!!

Post a Comment

 
Top