CMS WITH NATIVE DATA SOURCE


.
Step  1: Start the Wamp server and select phpMyAdmin.
Step 2: Create a database and a table with required fields.
Step 3: create a user and set the privileges.
Step 4: Enter the student details in the registration page.
Step 5: In the php file , set the connection to Mysql.
Step 6: Select the database and execute the query.
Step 7: Fetch the records into an array and display the records.
Step 8: Run the program in browser.

PHP CONSTRUCTS
1.      Connecting to data source
mysql_connect(“hostname”,”username”,”password”);

2.      Selecting the database
mysql_select_db(“database name”,connection variable);

3.      Executing the query
mysql_query(“sql statement”,connection variable);

4.      Fetching the records into array
mysql_fetch_array(execution variable);

5.      Refering value of each field
execution variable[‘field name’];
PROGRAM
Home.php
<html>
<body bgcolor="pink"><br><center>
<<div id="sarwan_login">
<form action="logk.php" method="post" name="L2" id="L2">
<label>User Name :</label> <input name="L1" type="text" class="inputfield" id="L1" maxlength="7"/><label>Password:</label><input class="inputfield" name="L2" type="password" id="L2"/><input class="button" type="submit" name="Submit" value="Login" />   </form> </div></body></html>
Logk.php
<?php
mysql_connect("localhost","sarwan","")or die(mysql_error());
mysql_select_db("mca")or die(mysql_error());
mysql_select_db("mca")or die(mysql_error());
$a= $_REQUEST['L1'];
$c=$_REQUEST['L2'];
$b=1;
$result = mysql_query("SELECT * FROM `student` WHERE regno='$a'");
while($row = mysql_fetch_array($result))
  {
if ($a==$row['regno']&& $c==$row['pwd'])
{
include("loginok.php");
$b=3;
}
else
$b=1;
}
if($b==1)
{echo"Invalid Username/Password  .";
include("index.php");}
?>
Student Details
<?php
include("config.php");
//mysql_connect("localhost","sarwan","sarwan")or //die(mysql_error());
$q= $_REQUEST['L1'];
$nam=1;
setcookie("user", $q,time()+3600);
setcookie("userq", $q,time()+3600);
$r= $_COOKIE["user"];
$result = mysql_query("SELECT * FROM `student` WHERE regno='$q'");
while($row = mysql_fetch_array($result))
  {
  ?>
print the value......................
<?php } ?>

0 comments: