Header Ads

Create a Simple Shopping Cart - E commerce with PHP & MySQL

Tutorial 1
In this tutorial we will be going to present you about the index page. It is starting with a Login system. We hope to add Sign up page later on this tutorial session. Let's look at step by step to make our shopping cart looks professional. 

index.php
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Welcome to my System</title>
<script type="text/javascript" src="lib_js/jquery2.0.3.js"></script>
<script type="text/javascript">
$(document).ready(function(e) {
    $("#btn_log").click(function(){

var uname=$("#unametxt").val();
var pwd=$("#pwdtxt").val();
if(uname!="" && pwd!=""){
$.post("check_log.php",
{
"username":uname,
"password":pwd
},function(data){
if(data==true)
location.href="system/";
else
$("#msg").text(data);
});
}
else{
$("#msg").text("Plaese enter username and password!");
}
});
});

</script>
<style type="text/css">
<!--
.style1 {font-family: Geneva, Arial, Helvetica, sans-serif}
-->
</style>
</head>

<body>
<h3 align="center" class="style1">Login System</h3>
<form method="post">
<table width="500" border="1" align="center" cellpadding="5" cellspacing="0" bordercolor="#00FF00" frame="box" rules="none">
<tr>
    <th colspan="2">
        <h4 class="style1">PLEASE ENTER USERNAME & PASSWORD </h4></th>
    </tr>
    <tr>
    <td><strong>Username</strong></td>
        <td>
        <input type="text" id="unametxt" size="35">
        </td>
    </tr>
    <tr>
    <td><strong>Password</strong></td>
        <td>
        <input type="password" id="pwdtxt" size="35">
        </td>
    </tr>
    <tr>
    <td></td>
        <td>
        <input type="button" id="btn_log" value="Login">
            <a href="#" class="register">Sign Up?</a>
        </td>
    </tr>
</table>
</form>
<div id="msg" style="color:red; font-size:30px; text-align:center; padding:15px;"></div>
</body>
</html>

connect.php
<?php
$dbuser="root";
$dbpassword="";
$db="course_db";
$host="localhost";
$conn=mysql_connect($host,$dbuser,$dbpassword) or die("Unable to connect to the database: ". mysql_error());
mysql_select_db($db) or die("Unable to Select the database: ".mysql_error());
?>


check_log.php
<?php
require_once("config/connect.php");
$uname=$_POST['username'];
$pwd=$_POST['password'];

$sql=mysql_query("SELECT * FROM users_tbl 
WHERE
uname='$uname' AND
password='$pwd'
");

$count=mysql_num_rows($sql);
if($count>0)
echo true;
else
echo "Login ort trov";
?>

If you have any doubts about the session, please don’t hesitate to ask from iTech Digest | Thank you! See you on next tutorial. 

No comments

Thank you very much for your ideas!