0% found this document useful (0 votes)
2 views

Sample Code for Group Assignment2

The document provides sample PHP code for database connection, data querying, and user session management. It includes examples of select and insert queries, as well as handling cookies and redirects. Additionally, it outlines requirements for a final project that includes various web pages and user functionalities.

Uploaded by

seanahmed626
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views

Sample Code for Group Assignment2

The document provides sample PHP code for database connection, data querying, and user session management. It includes examples of select and insert queries, as well as handling cookies and redirects. Additionally, it outlines requirements for a final project that includes various web pages and user functionalities.

Uploaded by

seanahmed626
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Sample Code to Help

OBJECTIVE:
i. Introduction to Databases with PHP

DB Connection

/*Connection Start*/ /*Connection End*/

<?php <?php
$host = 'localhost'; mysqli_close($link);
$user = ‘root'; ?>
$password = '';
$db = ‘lab';
$link = mysqli_connect($host, $user,
$password, $db);
?>

Data Query

/*Select Query*/

<?php
$email = ‘[email protected]‘;
$sql = 'SELECT * FROM user WHERE user_email='.$email; $result = mysqli_query($link,
$sql) or die(mysqli_error());
?>
/* Data Fetch*/

<?php
$noOfData = mysqli_num_rows($result);
while($row = mysqli_fetch_row($result)){
print_r($row);
}
?>

/* Insert Query*/

• <?php
$user_name = ‘Tanzilur Rahman’;
$user_email = ‘[email protected]’;
$password = md5(‘123456’);
date_default_timezone_set('Asia/Dhaka');
$currentTime = date('Y-m-d H:i:s');

$sqlInsert = 'INSERT INTO user (user_name, user_email, password, status, date_created)


VALUES (“ '.$user_name.‘ " ,“ '.$user_email.‘ “,” ’.$password.’ ”,1, "'.$currentTime.'" )';

$resultInsert = mysqli_query($link, $sqlInsert) or die(mysqli_error($link)); $lastInsertID =


mysqli_insert_id($link);
?>

PHP Session, Cookies & Redirect

*/PHP Session*/

<?php
session_start();
?>

*/PHP Cookies*/

<?php
$cookie_name = "user";
$cookie_value = "John Doe";
setcookie("TestCookie", $value, time()+3600);
?>

*/PHP Redirect*/

<?php
header('Location: http://www.aust.edu/'); die;
?>
Final Project Requirement: You must include following page/ content to your final project.
• Home Page
• About Us Page
• Contact Page
• Login & Registration Option
• User Profile Page
• All Service/All Product Page
• Service/Product Details Page

You might also like