NextIndexPrevious

Programs in PHP

23. Program to create a simple Registration form.

registration.php

<html> <head> </head> <body> <h4>Registration Form</h4> <form method="post" action="insert.php"> SNo :<input type="text" name="sno"><br> Name :<input type="text" name="name"><br> User name :<input type="text" name="uname"><br> Password :<input type="password" name="pwd"><br> <input type="submit" value="Register"> </form> </body> </html>

insert.php

<?php $conn = mysqli_connect('servername','username','password','databasename'); if(!$conn) { die('Connection failed!'.mysqli_error($conn)); } $sno = $_POST['sno']; $name = $_POST['name']; $uname = $_POST['uname']; $pwd = $_POST['pwd']; $sql = "INSERT INTO tablename(sno, name, uname, pwd) VALUES('$sno', '$name','$uname', '$pwd')"; if(mysqli_query($conn,$sql)) { echo "Registerd Successfully"; } else { echo mysqli_error($conn); } ?> ------------------------------------------------------------- Note: When we using XAMPP or WAMP, servername = localhost, username = root, password is empty.

Father of PHP

Rasmus Lerdorf

Rasmus Lerdorf

Born: November 22, 1968, Greenland