Login With Session And Customer Add In PHP For Beginners
Index.php
html
<h2 align=Right>Please Login ....</h2>
<form Action="Index.php" Method="POST">
<table border=1 CellPadding=5 CellSpacing=5 align=Right>
<tr>
<td>UserName</td>
<td><Input Type=Text name=txtName Required /></td>
</tr>
<tr>
<td>Password</td>
<td><Input Type=Password name=txtPass Required></td>
</tr>
<tr>
<td>.</td>
<td Align=Right><Input Type=Submit name=btnLogin value=Login></td>
</tr>
</table>
</form>
<form Action="Index.php" Method="POST">
<table border=1 CellPadding=5 CellSpacing=5 align=Right>
<tr>
<td>UserName</td>
<td><Input Type=Text name=txtName Required /></td>
</tr>
<tr>
<td>Password</td>
<td><Input Type=Password name=txtPass Required></td>
</tr>
<tr>
<td>.</td>
<td Align=Right><Input Type=Submit name=btnLogin value=Login></td>
</tr>
</table>
</form>
php
<?php
session_start();
$_SESSION['UName'] = "";
if(isset($_POST['btnLogin']))
{
$UN = $_POST['txtName'];
$UP = $_POST['txtPass'];
$A = mysql_connect("LocalHost","root","");
mysql_select_db("AirLineDB",$A);
$B = mysql_query("Select UID from tblUsers where UName='$UN' and UPass='$UP'",$A);
mysql_close($A);
if(mysql_num_rows($B)>0)
{
$_SESSION['UName']=$UN;
echo "<meta http-equiv='Refresh'; Content='0; URL=Home.php';>";
}
else
{ $Err="Try again...."; }
}
?>
session_start();
$_SESSION['UName'] = "";
if(isset($_POST['btnLogin']))
{
$UN = $_POST['txtName'];
$UP = $_POST['txtPass'];
$A = mysql_connect("LocalHost","root","");
mysql_select_db("AirLineDB",$A);
$B = mysql_query("Select UID from tblUsers where UName='$UN' and UPass='$UP'",$A);
mysql_close($A);
if(mysql_num_rows($B)>0)
{
$_SESSION['UName']=$UN;
echo "<meta http-equiv='Refresh'; Content='0; URL=Home.php';>";
}
else
{ $Err="Try again...."; }
}
?>
Home.php
html
<h2 align=Center>Add New Customer</h2>
<form action="Home.php" Method="POST">
<table border=1 CellPadding=5 CellSpacing=5 Align=center>
<tr align=center BGColor=aqua><td colspan=2>Flight Information</td></tr>
<tr>
<td>Customer Name</td>
<td><input type=Text name=txtName Required></td>
</tr>
<tr>
<td>Customer N-I-C</td>
<td><input type=Text name=txtCNIC Required></td>
</tr>
<tr>
<td>Select AirLine</td>
<td><Select name=cmbAL Style=Width:145>
<option Selected>Emirates</option>
<option>Lufthansa</option>
<option>Air Blue</option>
<option>Bhoja Air</option>
<option>Fly Dubai</option>
<option>P-I-A</option>
</select></td>
</tr>
<tr>
<td>From City</td>
<td><Select name=cmbFC Style=Width:145>
<option>Karachi</option>
<option Selected>Lahore</option>
<option>Islamabad</option>
<option>Hyderabad</option>
<option>Peshawar</option>
<option>Quetta</option>
</select></td>
</tr>
<tr>
<td>To City</td>
<td><Select name=cmbTC Style=Width:145>
<option Selected>Karachi</option>
<option>Lahore</option>
<option>Islamabad</option>
<option>Hyderabad</option>
<option>Peshawar</option>
<option>Quetta</option>
</select></td>
</tr>
<tr>
<td>Enter Fare</td>
<td><input type=Text name=txtFare Required></td>
</tr>
<tr>
<td>.</td>
<td align=right><input type=Submit name=btnSave value=Save></td>
</tr>
</table>
</form>
<form action="Home.php" Method="POST">
<table border=1 CellPadding=5 CellSpacing=5 Align=center>
<tr align=center BGColor=aqua><td colspan=2>Flight Information</td></tr>
<tr>
<td>Customer Name</td>
<td><input type=Text name=txtName Required></td>
</tr>
<tr>
<td>Customer N-I-C</td>
<td><input type=Text name=txtCNIC Required></td>
</tr>
<tr>
<td>Select AirLine</td>
<td><Select name=cmbAL Style=Width:145>
<option Selected>Emirates</option>
<option>Lufthansa</option>
<option>Air Blue</option>
<option>Bhoja Air</option>
<option>Fly Dubai</option>
<option>P-I-A</option>
</select></td>
</tr>
<tr>
<td>From City</td>
<td><Select name=cmbFC Style=Width:145>
<option>Karachi</option>
<option Selected>Lahore</option>
<option>Islamabad</option>
<option>Hyderabad</option>
<option>Peshawar</option>
<option>Quetta</option>
</select></td>
</tr>
<tr>
<td>To City</td>
<td><Select name=cmbTC Style=Width:145>
<option Selected>Karachi</option>
<option>Lahore</option>
<option>Islamabad</option>
<option>Hyderabad</option>
<option>Peshawar</option>
<option>Quetta</option>
</select></td>
</tr>
<tr>
<td>Enter Fare</td>
<td><input type=Text name=txtFare Required></td>
</tr>
<tr>
<td>.</td>
<td align=right><input type=Submit name=btnSave value=Save></td>
</tr>
</table>
</form>
PHP
<?php
session_start();
if($_SESSION['UName']=="")
{ echo "<meta http-equiv='Refresh'; Content='0; URL=Index.php';>"; exit; }
if(isset($_GET['A']))
{
$AID = $_GET['A'];
$A = mysql_connect("LocalHost","root","");
mysql_select_db("AirLineDB",$A);
mysql_query("Update tblAirLine set Status='False' Where AID='$AID'",$A);
mysql_close($A);
}
?>
<?php
if(isset($_POST['btnSave']))
{
$PN = $_POST['txtName'];
$NC = $_POST['txtCNIC'];
$AL = $_POST['cmbAL'];
$FC = $_POST['cmbFC'];
$TC = $_POST['cmbTC'];
$FR = $_POST['txtFare'];
$A = mysql_connect("LocalHost","root","");
mysql_select_db("AirLineDB",$A);
mysql_query("Insert into tblAirLine values ('','$PN','$NC','$AL','$FC','$TC','$FR','True')",$A);
mysql_close($A);
}
?>
session_start();
if($_SESSION['UName']=="")
{ echo "<meta http-equiv='Refresh'; Content='0; URL=Index.php';>"; exit; }
if(isset($_GET['A']))
{
$AID = $_GET['A'];
$A = mysql_connect("LocalHost","root","");
mysql_select_db("AirLineDB",$A);
mysql_query("Update tblAirLine set Status='False' Where AID='$AID'",$A);
mysql_close($A);
}
?>
<?php
if(isset($_POST['btnSave']))
{
$PN = $_POST['txtName'];
$NC = $_POST['txtCNIC'];
$AL = $_POST['cmbAL'];
$FC = $_POST['cmbFC'];
$TC = $_POST['cmbTC'];
$FR = $_POST['txtFare'];
$A = mysql_connect("LocalHost","root","");
mysql_select_db("AirLineDB",$A);
mysql_query("Insert into tblAirLine values ('','$PN','$NC','$AL','$FC','$TC','$FR','True')",$A);
mysql_close($A);
}
?>
No comments:
Post a Comment