Welcome to Knowledge Website
Learn basic php
Web pages designed with html coding are usually called static web pages as they have no dynamic data interactions. Yes, you could have user inputs via a form (including some check boxes, radio buttons, selections interactions) and display them back. But no actual data interaction utilizing a real database. In other words, you can statically use a html form inputs to display right back to user, but cannot store all the data for later use or display. Here comes Hypertext Preprocessor (PHP) coding. PHP allows us to interact with a database, such as, MySql etc. One catch though, a web page containing php coding cannot run just by opening in a browser. A server has to support php coding. An php page has extension of .php instead of .html or .htm used in a regular html page.
Example of a php coding:
<?php
$con = mysql_connect("server", "database", "password") or die("Cannot connect to db!" . mysql_error());
mysql_select_db("database name") or die("Unable to select db!" . mysql_error());
$sql = "select * from login where username = '" . $_POST['uname'] . "' and password = '" . $_POST['pwd'] . "'";
$result1 = mysql_query($sql) or die("Problem to run query!");
$rows = mysql_num_rows($result1);
if ($rows < 0 or $rows == 0 or $rows > 1)
echo ("Unsuccessful login! Please try again!");
else
{
$result2 = mysql_fetch_assoc($result1);
$sql2 = "select customer.firstName from customer where customerId = '" . $result2['customerId'] . "'";
$result3 = mysql_query($sql2) or die("Problem to run sql2" . mysql_error());
$rows = mysql_fetch_assoc($result3);
echo ("Hi " . $rows['firstName'] . ", you have been successfully login now!");
// start a session for the user
session_start();
$_SESSION['username'] = $_POST['uname'];
}
?>
To learn more about php click here.
