Quoteconfig.php
<?php
define('DB_SERVER','localhost');
define('DB_USER','root'); // default username is root for offline server
define('DB_PASS' ,''); //password must be empty since you are working offline
define('DB_NAME', 'database_name'); // input your database name that you created
$con = mysqli_connect(DB_SERVER,DB_USER,DB_PASS,DB_NAME);
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
<table>
<tr>
<th>#</th>
<th>Fullname</th>
<th>Email</th>
<th>Phone Number</th>
<th>Time Regd.</th>
</tr>
<?php
$sql = "SELECT * from table_name ORDER BY 'id' ASC";
// To call all registered investors
$result = mysqli_query($con, $sql);
$cnt=1;
while($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
{
?>
<tr>
<th><?php echo ($cnt);?></th>
<th><?php echo ($row['fullname']);?></th>
<th><?php echo ($row['email']);?></th>
<th><?php echo ($row['phone']);?></th>
<th><?php echo ($row['time']);?></th>
</tr>
<?php $cnt=$cnt+1;} ?>
</table>
QuoteHow to echo time format <?php echo htmlentities($row['time']); ?>
<td><?php $go3= date('d, M Y'); $v3= htmlentities($row['time']); echo date('d, M Y', strtotime($v3));?></td>
<td><?php $suc=$row['status']; if($suc== "") { echo '<span class="text-primary">Inactive</span>'; } ?> <?php if($suc=="Credited") { echo '<span class="text-success">Credited</span>'; } ?></td>
<?php
define('DB_SERVER','localhost');
define('DB_USER','root');
define('DB_PASS' ,'');
define('DB_NAME', 'demos');
$con = mysqli_connect(DB_SERVER,DB_USER,DB_PASS,DB_NAME);
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
This PHP script is called inside the login script. It presents the user with a HTML form to enter username and password. In case the form is submitted, PHP runs a SELECT query to retrieve a row in the admin table where the username and passcode matches with the user inputs.<?php
session_start();
include_once("config.php");
if(isset($_POST['login']))
{
$email=$_POST['email'];
$password=md5($_POST['password']);
$ret= mysqli_query($con,"SELECT * FROM userregistration WHERE email='$email' and password='$password'");
$num=mysqli_fetch_array($ret);
$status=$num['status'];
if($num>0)
{
if($status==0)
{
$_SESSION['action1']="Verify your Email Id by clicking the link In your mailbox";
}
else {
$_SESSION['login']=$email;
$_SESSION['id']=$num['id'];
$_SESSION['name']=$num['name'];
$extra="welcome.php";
$host=$_SERVER['HTTP_HOST'];
$uri=rtrim(dirname($_SERVER['PHP_SELF']),'/\\');
header("location:http://$host$uri/$extra");
exit();
}
}
else
{
$_SESSION['action1']="Invalid username or password";
$extra="login.php";
$host = $_SERVER['HTTP_HOST'];
$uri = rtrim(dirname($_SERVER['PHP_SELF']),'/\\');
header("location:http://$host$uri/$extra");
exit();
}
}
?>
<?php echo $_SESSION['action1']; ?><?php echo $_SESSION['action1']="";?>
<?php
session_start();
include_once("config.php");
if($_SESSION['login'])
{
?>
<?php echo $_SESSION['name']; ?>
To echo login user name etc.<?php
session_start();
$_SESSION['login']=="";
session_unset();
$_SESSION['action1']="You have logged out successfully..!";
?>
<script language="javascript">
document.location="login.php";
</script>
$password=md5($_POST['password']);
QuoteWe will be creating the table below directly from Mysqli database
CREATE TABLE MyGuests (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
)
INSERT INTO table_name (column1, column2, column3,...)
VALUES (value1, value2, value3,...)
QuoteNote: If a column is AUTO_INCREMENT (like the "id" column) or TIMESTAMP with default update of current_timesamp (like the "reg_date" column), it is no need to be specified in the SQL query; MySQL will automatically add the value.
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', 'john@example.com')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>
QuoteNote: Before connecting to Mysql ot database, it is imperative to start up your xampp engine.
QuoteNote: For this tutorial, we will be working only with MySqli.
<?php
$servername = "localhost";
$username = "username";
$password = "password";
// Create connection
$conn = mysqli_connect($servername, $username, $password);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";
?>
QuoteClick the next class to learn about to create a database table.
SELECT LastName FROM Employees
include 'filename';
or
require 'filename';
<html>
<body>
<h1>Welcome to my home page!</h1>
<p>Some text.</p>
<p>Some more text.</p>
<?php include 'footer.php';?>
</body>
</html>
QuoteCREATIVITY is one of the facets of web development.
<?php
echo "Today is " . date("Y/m/d") . "<br>";
echo "Today is " . date("Y.m.d") . "<br>";
echo "Today is " . date("Y-m-d") . "<br>";
echo "Today is " . date("l");
?>
<html>
<body>
<form action="welcome.php" method="POST">
Name: <input type="text" name="name" id="name"><br>
E-mail: <input type="email" name="email" id="email"><br>
<input type="submit">
</form>
</body>
</html>
<html>
<body>
Welcome <?php echo $_POST["name"]; ?><br>
Your email address is: <?php echo $_POST["email"]; ?>
</body>
</html>
Welcome John
Your email address is john.doe@example.com
QuoteDevelopers prefer POST for sending form data.
<?php
if (condition) {
// code to be executed if condition is true;
} else {
// code to be executed if condition is false;
}
?>
<?php
$t = date("H");
if ($t < "20") {
echo "Have a good day!";
} else {
echo "Have a good night!";
}
?>
if (condition) {
code to be executed if this condition is true;
} elseif (condition) {
// code to be executed if first condition is false and this condition is true;
} else {
// code to be executed if all conditions are false;
}
<?php
$t = date("H");
if ($t < "10") {
echo "Have a good morning!";
} elseif ($t < "20") {
echo "Have a good day!";
} else {
echo "Have a good night!";
}
?>
<?php
if (condition) {
// code to be executed if condition is true;
} else {
// code to be executed if condition is false;
}
?>
<?php
$t = date("H");
if ($t < "20") {
echo "Have a good day!";
} else {
echo "Have a good night!";
}
?>
if (condition) {
code to be executed if this condition is true;
} elseif (condition) {
// code to be executed if first condition is false and this condition is true;
} else {
// code to be executed if all conditions are false;
}
<?php
$t = date("H");
if ($t < "10") {
echo "Have a good morning!";
} elseif ($t < "20") {
echo "Have a good day!";
} else {
echo "Have a good night!";
}
?>