Php-Tutorial






Hey! people today i will be telling how you can create a sign up page using Php+Mysql. it actually very much simple. sample codes are here you just need to create database using mysql. Validation part is not been done.


"<?php

echo "<form action='insert.php' method='post'>";/* it is actually the method after sign up button clicked insert.php button will be clicked and through post method data will be sent.
echo "<table align='center' border='1'>";
echo "<tr>";
echo "<td colspan='2' align='center' >";
echo "<b>User Data :</b>";
echo "</td>";
echo "</tr>";

echo "<br>";
echo "<br>";

echo "<tr>";
echo "<td>";
echo "AADHAAR:";
echo "</td>";
echo "<td>";
echo "<input type='text' name='txtadhar'>";
echo "</td>";
echo "<tr>";

echo "<tr>";
echo "<td>";
echo "EMAIL:";
echo "</td>";
echo "<td>";
echo "<input type='text' name='txtemail'>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td>";
echo "Gender:";
echo "</td>";
echo "<td>";
echo "<select name='Gender'>";
echo "<option value='M'>Male</option>";
echo "<option value='F'>Female</option>";
echo "</select>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td>";
echo "PASSWORD:";
echo "</td>";
echo "<td>";
echo "<input type='password' name='txtpswd'>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td>";
echo "NAME:";
echo "</td>";
echo "<td>";
echo "<input type='text' name='txtname'>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td>";
echo "ADDRESS:";
echo "</td>";
echo "<td>";
echo "<input type='text' name='txtaddress'>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td>";
echo "MOBILE:";
echo "</td>";
echo "<td>";
echo "<input type='text' name='txtmobile'>";
echo "</td>";
echo "</tr>";

echo "<tr>";
echo "<td colspan='2' align='center'>";
echo "<input type='Submit' value='Signup'>";
echo "</td>";
echo "</tr>";


echo "</table>";
echo "</form>";

?>"

Insert.php(Database connectivity sql quarries will be code here here)


<?php
$txtadhar=$_POST['txtadhar'];/* first "$txtadhar"variable decleration. then method "POST"then field name.
$txtemail=$_POST['txtemail'];
$Gender=$_POST['Gender'];
$txtpswd=$_POST['txtpswd'];
$txtname=$_POST['txtname'];
$txtaddress=$_POST['txtaddress'];
$txtmobile=$_POST['txtmobile'];

$link=mysql_connect('localhost','root','');/*Creating SQl connection object
if(!$link)
{
  die('Could not connect:'.mysql_error());
}
else
{
    echo 'Connected Successfully<br><br>';
}
mysql_select_db('sap') or die('Could not select database');/*database selection my 1 name is"sap".

$query="INSERT INTO registration VALUES('$txtadhar','$txtemail','$txtpswd','$txtname','$txtaddress','$txtmobile','$Gender')";/* sql insert quary.
$result=@mysql_query($query);/* quarry validation storing query result. 
if($result)
 {
   echo "Record added successfully";
 }
else
 {
   die("Query failed");
 }


mysql_close($link);/* for connection closing.

?>

If you need further assistant don't hesitate to contact me mail2tonnie@gmail.com

_________________________________________________________________________________



As my previous post was on User sign up, naturally now comes the login screen this one also very easy.
if take the variable the check the data input with the table then start the session, after check the session at the beginning the every page, if the session is active print logout button with user-id/name. lets see in the code. I have created the stdent type in drop down menu. but first learn simple login.






CODE for LOGIN SCREEN Table and all.

<?php
echo "<form action='validate.php' method='post'>";
?>
<html>
<head><h1><font color="purple"><u>EXISTING USER</u></font></h1></head>
<body bgcolor="navyblue">
<table>
<tr>
<td>EMAIL ID:</td><td><INPUT TYPE = "TEXT" NAME = "txtemail" value=""><BR></td>
</tr>
<tr>
<td>PASSWORD:</td><td><INPUT TYPE = "PASSWORD" NAME = "txtpswd" value=""><BR></td>
</tr>
<tr>
<td>ENTER STUDENT REGISTRATION NO.:</td><td><SELECT name = "t">
<OPTION>User</OPTION>
<OPTION>Administator</OPTION></td>
</tr>
<tr>
<td></td>
<td>
<INPUT TYPE = "SUBMIT" VALUE = "LOGIN">
</td>
</tr>
</table>
</body>
</html>

CODE FOR validate.php or main php code for LOGIN.


<?php
session_start();

$errmsg_arr=array();
$errflag=false;
function clean($str)
{
  $str=@trim($str);
  if(get_magic_quotes_gpc())
  {
   $str=stripslashes($str);
  }
  return($str);
}

$txtemail=clean($_POST['txtemail']);
$txtPswd=clean($_POST['txtpswd']);

$link=mysql_connect('localhost','root','');
$row=0;
if(!$link)
 {
  die('Could not connect:'.mysql_error());
 }
else
    echo "connection successful";
mysql_select_db('sap') or die('Could not select database');

$query="SELECT * FROM registration where email='".$txtemail."' and pswd= '".$txtPswd."'";

$result=mysql_query($query) or die('Query failed:'.mysql_error());

if(!$result)
 {
    die('Query failed1:'.mysql_error());
 }

//$row=mysql_fetch_assoc($result);
$row_num=mysql_num_rows($result);

if($row_num==1)
 {
  $_SESSION['user']=$txtemail;
  echo "login Successful";
  //header("location:main_frame.htm");
 }
else
 {
    echo "Incorrect username or password";
 }

?>

No comments:

Post a Comment