0% found this document useful (0 votes)
11 views7 pages

Lalaineretardophpsamplecode

1) The document provides sample code for a login page and user verification using PHP, HTML, CSS, and MySQL. 2) It includes code for a login form, form validation on the server, and sessions to keep users logged in across pages. 3) The document also includes sample code for a student registration form that collects and displays user input using PHP and HTML forms.

Uploaded by

Lalaine Retardo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views7 pages

Lalaineretardophpsamplecode

1) The document provides sample code for a login page and user verification using PHP, HTML, CSS, and MySQL. 2) It includes code for a login form, form validation on the server, and sessions to keep users logged in across pages. 3) The document also includes sample code for a student registration form that collects and displays user input using PHP and HTML forms.

Uploaded by

Lalaine Retardo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Name: Lalaine Temperatura Retardo

BSIT 2 SET A
Sample code of Log In Page using PHP code

//
login_page.php

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


User Name:<br>
<input type="text" name="username"><br><br>
Password:<br>
<input type="password" name="password"><br><br>
<input type="submit" name="submit" value="Login">
</form>
verify.php

<?php
if(isset($_POST['submit'])){
$dbHost = "localhost"; //Location Of Database usually its localhost
$dbUser = "xxxx"; //Database User Name
$dbPass = "xxxxxx"; //Database Password
$dbDatabase = "db_name"; //Database Name

$db = mysql_connect($dbHost,$dbUser,$dbPass)or die("Error connecting to database.");


//Connect to the databasse
mysql_select_db($dbDatabase, $db)or die("Couldn't select the database.");
//Selects the database

/*
The Above code can be in a different file, then you can place include'filename.php'; instead.
*/

//Lets search the databse for the user name and password
//Choose some sort of password encryption, I choose sha256
//Password function (Not In all versions of MySQL).
$usr = mysql_real_escape_string($_POST['username']);
$pas = hash('sha256', mysql_real_escape_string($_POST['password']));
$sql = mysql_query("SELECT * FROM users_table
WHERE username='$usr' AND
password='$pas'
LIMIT 1");
if(mysql_num_rows($sql) == 1){
$row = mysql_fetch_array($sql);
session_start();
$_SESSION['username'] = $row['username'];
$_SESSION['fname'] = $row['first_name'];
$_SESSION['lname'] = $row['last_name'];
$_SESSION['logged'] = TRUE;
header("Location: users_page.php"); // Modify to go to the page you would like
exit;
}else{
header("Location: login_page.php");
exit;
}
}else{ //If the form button wasn't submitted go to the index page, or login page
header("Location: index.php");
exit;
}
?>
users_page.php
<?php
session_start();
if(!$_SESSION['logged']){
header("Location: login_page.php");
exit;
}
echo 'Welcome, '.$_SESSION['username'];
?>

Sample code using PHP, HTML and CSS

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title></title>
</head>
<body>
<style>
body{
font-family: "Lucida Console", "Courier New", monospace;
}
form{
margin: 0px;
border: solid 1px;
border - color : coral;
border-collapse: collapse;
padding: 5px;
text-align: center;
width: 450px;
background-color: light pink;
column-rule-color: yellow;
align-items: center;
color: blue ;
}
h2{
text-align: center;
align-items: center;
background-color: blue;
}
h3{text-align: center;
align-items: center;
background-color: blue;
}
div {
margin: 0px;
border: solid 1px;
border - color : coral;
border-collapse: separate;
padding: 5px;
text-align: left;
width: 450px;
background-color:light pink;
column-rule-color:yellow;
}
</style>

<h2>Student Registration Form</h2>


<form method="get" >
Student ID : <input type="text" name="studentIdTxt" required autocomplete="off">

<br><br>

Student Name : <input type="text" name="studentNameTxt" required


autocomplete="off">

<br><br>

Student Address : <input type="text" name="studentAddressTxt" required


autocomplete="off">

<br><br>

Email : <input type="email" name="emailTxt" required autocomplete="off">

<br><br>

Course : <select name="courseTxt">


<option value="">Select course</option>
<option value="BSIT">BSIT</option>
<option value="BSBA">BSBA</option>
<option value="BSED">BSED</option>
<option value="BEED">BEED</option>
</select>

<br><br>
Year Level : <select name="yearTxt" required>
<option value="">Select Year Level</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>

<br><br>

Gender : <select name="genderTxt" required>


<option value="">Gender</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>

<br><br>

Birth Date:<input type= "date" id="birthday" name="birthday">

<br><br>

<input type="checkbox" name="checkBox" required > I hereby certify that the foregoing
information is true and accurate.<br>Are you ready to submit?
<br><br>

<input type="submit" name="submitBtn" value="Submit">

</form>
<hr>
<h3>SUMMARY</h3>
<div>
<?php

if (isset($_GET['submitBtn'])) {
?>

<span>Student ID: <?= $_GET['studentIdTxt']; ?></span>


<br>
<span>Student name: <?= $_GET['studentNameTxt']; ?></span>
<br>
<span>Student address: <?= $_GET['studentAddressTxt'];
?></span>
<br>
<span>Student email: <?= $_GET['emailTxt']; ?></span>
<br>
<span>Student Course & year level: <?= $_GET['courseTxt']." - ".
$_GET['yearTxt']; ?></span>
<br>
<span>Student gender: <?= $_GET['genderTxt']; ?></span>
<br>

<?php
}

?>
</div>
</body>
</html>

You might also like