Вы находитесь на странице: 1из 4

DATABASE CREATION AND TABLE CREATION SCRIPT

<?php

$con=mysql_connect("localhost","root","");

if($con){

echo"connected to the server";

}else{

echo"not connected to the server";

$sql="create database student_regisration";

$db=mysql_query($sql,$con);

/*if($db){

echo"database created";

}else{

echo"database not created".mysql_error();

}*/

$db_select=mysql_select_db("student_regisration",$con);

if($db_select){

echo"database selected";

}else{

echo"database not selected".mysql_error();

$tb="create table registration(firstName varchar(20) not null,lastName varchar(20) not null,userName varchar(15) not null,password
varchar(20) primary key,address varchar(50) not null,gender varchar(10) not null,course varchar(5) not null)";

$tb_running=mysql_query($tb,$con);

if($tb_running){

echo"table created";

}else{

echo"table not created".mysql_error();

?>
REGISTRATION AND INSERTION SCRIPT

<html><head><title>Registration form</title></head><body>

<form action="insert.php" method="post">

First Name:<br>

<input type="text" name="fname"><br>

Last Name<br>

<input type="text" name="lname"><br>

User Name<br>

<input type="text" name="uname"><br>

Password<br>

<input type="password" name="pass"><br>

Address<br>

<textarea name="add" cols="15" rows="5">

</textarea><br>

Gender<br>

<input type="radio" name="gender" value="female">Female

<input type="radio" name="gender" value="Male">Male<br>

Course<br>

<select name="course">

<option value="BIT">BIT </option>

<option value="BCS">BCS </option>

<option value="BBC">BBC </option>

<option value="DCS">DCS </option>

<option value="DIT">DIT </option>

<option value="DBC">DBC </option>

</select><br>

<input type="submit" value="Register">

<input type="reset" value="Cancel">

</form>

</body>

</html>
<html><head><title>Login form</title></head>

<body>

<?php

$con=mysql_connect("localhost","root","");

$sql=mysql_select_db("student_regisration",$con);

if($sql){

echo"database selected";

}else{

echo"database not selected".mysql_error();

$insert="insert into registration


values('$_POST[fname]','$_POST[lname]','$_POST[uname]',md5('$_POST[pass]'),'$_POST[add]','$_POST[gender]','$_POST[course]')";

$insertion=mysql_query($insert,$con);

if($insertion){

echo"data inserted";

}else{

echo"data not inserted".mysql_error();

?>
LOGIN FORM PLUS SCRIPT

<form action="log.php" method="post">

User name <br>

<input type="text" name="uname"><br>

Password<br>

<input type="password" name="pass"><br>

<input type="submit" value="LOGIN">

<input type="reset" value="cancel">

</form>

</body>

</html>

<?php

$con=mysql_connect("localhost","root","");

$db_select=mysql_select_db("student_regisration",$con);

$username=$_POST['uname'];

$password=$_POST['pass'];

$select="select * from registration where userName='$username' AND password='$password'";

$result=mysql_query($select,$con);

$count=mysql_num_rows($result);

if($count >0){

echo"you have successfully loged in";

}else{

echo"Either username or password is incorrect".mysql_error();

?>

Вам также может понравиться