Objectives The aim of this project is to implement a web database application to
ID: 3607073 • Letter: O
Question
Objectives
The aim of this project is to implement a web database application to support online advertisement of yard sales.
Milestone 2.
Create database, setup database schema in mysql.
Implement the following functionality: a) a user can register him/herself through your website; b) if registered, a user can login to the system and create a yard sale.
This is coded in HTML/PHP/MYSQL
I have the html webpage up and running but once I put in a username and password I can't get anything to work with printing out a database.
1) Folder ca:
index.html:
<html>
<body background="z.jpg">
<table align="center"background="bg.jpg" width="1004" height="84">
<tr><th align="center" font> Create an Acccount </th></tr>
</table>
<table align="center" background="img01.gif" width="1010" height="40">
<tr><td color="red"><marquee behavior="alternate" scrollamount="10">Online sales</marquee></td></tr>
</table>
<br>
<form method="post" action="submit.php" name="form">
<table align="center" background="tb.gif">
<tr>
<td colspan="0" align="left"><big>Create an account <br /><br /></big></td>
</tr>
<tr>
<td align="left">Name</td>
<td align="left"><input name="name" type="text" maxlength="20"/></td>
</tr>
<tr>
<td align="left">Username</td>
<td align="left"><input name="usrname" type="text" maxlength="20"/></td>
</tr>
<tr>
<td align="left">Password</td>
<td align="left"><input type="password" name="pasword" maxlength="10" /></td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" value="Create an Account" /></td>
</tr>
</table>
</form>
<table align="center" background="img01.gif" width="1010" height="40">
<tr><td color="red"><marquee behavior="alternate" scrollamount="10">Online sales</marquee></td></tr>
</table>
</body>
</html>
submit.php:
<html>
<body body background="z.jpg"></body>
<table align="center"background="bg.jpg" width="1004" height="84">
<tr><th align="center" font> Create an Acccount </th></tr>
</table>
<table align="center" background="img01.gif" width="1010" height="50">
<tr>
<td align="center" alt="Go back" title="Go back"><a href="../login"><blink>Go back</blink></td>
</tr>
</table>
<br><br>
<form method="post" action="submit.php" name="form">
<table align="center" background="tb.gif">
<tr>
<td colspan="0" align="left"><big>Create an account <br /><br /></big></td>
</tr>
<tr>
<td align="left">Name</td>
<td align="left"><input name="name" type="text" maxlength="20"/></td>
</tr>
<tr>
<td align="left">Username</td>
<td align="left"><input name="usrname" type="text" maxlength="20"/></td>
</tr>
<tr>
<td align="left">Password</td>
<td align="left"><input type="password" name="pasword" maxlength="10" /></td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" value="Create an Account" /></td>
</tr>
</table>
</form>
<table align="center" background="img01.gif" width="1010" height="40">
<tr>
<td color="red"><marquee behavior="alternate" scrollamount="20">Online sales</marquee></td></tr>
</table>
</html>
<?php
$name=$_POST['name'];
$usrname=$_POST['usrname'];
$pasword=$_POST['pasword'];
if(!$usrname)
{
echo "<script language='javascript'>alert('Sorry first fill the all fields....')</script>";
}
else
{
$con = mysql_connect("localhost","root","moni");
if (!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db("pro");
mysql_query("INSERT INTO cac (name,usrname,pasword) VALUES ('$name','$usrname','$pasword')");
mysql_close($con);
echo "<script language='javascript'>alert('Hai ur account has been created......u can login now...')</script>";
}
?>
2) login folder
loginauth.php
<?php
function setmycookie()
{
setcookie("userauth",$uname,time()+3600,"/");
}
if(isset($_POST['name']))
{
}
else
{
// do nothing, when user did not submitted the form.
}
?>
index.php:
<style type="text/css">
body{
background: url('back.jpg');
}
h1{
font-family: Times New Roman;
color: white;
font-size: 40px;
}
table{
padding: 50px 20px;
color:blue;
}
td input[type=text]
{
border: 1px lightblue solid;
padding: 2px;
width: 130px;
}
td input[type=password]
{
border: 1px lightblue solid;
width:130px;
color:blue;
}
</style>
<form method="post" action="">
<table align="right" background="tb.gif">
<tr>
<td> Username </td>
<td> <input type="text" name="name"> </td>
</tr>
<tr>
<td> Password </td>
<td> <input type="password" name="password"> </td>
</tr>
<tr>
<td colspan="4" align="left"><br>
<input type="submit" value="Log in" name='login'>
</td>
</tr>
<tr><td><br><br><a align="right" href="../ca" alink="blue" vlink="blue" link="blue">New for site <br>Create an account</td></tr>
</table>
</form>
<body><h1 background="h1.gif">Welcome To Online Yard sales</h1></body>
<?php
function setmycookie()
{
setcookie("userauth",$_POST['name'],time()+3600,"/");
}
if(isset($_COOKIE['userauth']))
{
header("Location: ../home/");
}
else
{
if(isset($_POST['login']))
{
$name=$_POST['name'];
$pass=$_POST['password'];
$connect=mysql_connect("localhost","root","moni");
mysql_select_db("pro");
$query=mysql_query("SELECT * FROM cac WHERE usrname='$name' && pasword='$pass'");
$count=mysql_num_rows($query);
if($count==1)
{
header("Location: ../home/");
setmycookie();
}
elseif($count==0)
{
echo "<a href="../login/">Login</a>";
echo "<script language='javascript'>alert('Invalid username and password.')</script>";
}
else
{
echo "Please contact the site administrator.<br/>Error: Duplicates exists";
echo "<script language='javascript'>alert('Plese Contact Authors..')</script>";
}
}
else
{
//do nothing.
}
}
?>
checklogin.php:
<?php
if(isset($_COOKIE['userauth']))
{
//do nothing.
}
else
{
header("Location: ../login/");
}
?>
index1.html : C O file:///E/RGUKTSE%20pro/ca/index1.html Apps RGUKTN Alumni NetE How to Make a WecUPSC Recruit net m upload Resume Fr " Digital ValleySummit od ng Dee Learning ude Learn the Basics of DCSE 30 Create an Acccount Online sales Create an account Name Username Password Create an Account Online salesExplanation / Answer
In Above code evrything is right every thing is working correctly but in index.php you used setmycookie function after the header location and it does not set the cookie and this is why your home page is not opening.
here is the modified code : -------------------------------->>>>>>>>>>>>>>>>>>>>>>>>>>
<style type="text/css">
body{
background: url('back.jpg');
}
h1{
font-family: Times New Roman;
color: white;
font-size: 40px;
}
table{
padding: 50px 20px;
color:blue;
}
td input[type=text]
{
border: 1px lightblue solid;
padding: 2px;
width: 130px;
}
td input[type=password]
{
border: 1px lightblue solid;
width:130px;
color:blue;
}
</style>
<form method="post" action="index.php">
<table align="right" background="tb.gif">
<tr>
<td> Username </td>
<td> <input type="text" name="name"> </td>
</tr>
<tr>
<td> Password </td>
<td> <input type="password" name="password"> </td>
</tr>
<tr>
<td colspan="4" align="left"><br>
<input type="submit" value="Log in" name='login'>
</td>
</tr>
<tr><td><br><br><a align="right" href="../ca" alink="blue" vlink="blue" link="blue">New for site <br>Create an account</td></tr>
</table>
</form>
<body><h1 background="h1.gif">Welcome To Online Yard sales</h1></body>
<?php
function setmycookie()
{
setcookie("userauth",$_POST['name'],time()+3600,"/");
}
if(isset($_COOKIE['userauth']))
{
header("Location: ../home/");
}
else
{
if(isset($_POST['login']))
{
$name=$_POST['name'];
$pass=$_POST['password'];
$connect=mysql_connect("localhost","root","moni");
mysql_select_db("pro");
$query=mysql_query("SELECT * FROM cac WHERE usrname='$name' && pasword='$pass'");
$count=mysql_num_rows($query);
if($count==1)
{
setmycookie();//changed code
header("Location: ../home/");
}
elseif($count==0)
{
echo "<a href="../login/">Login</a>";
echo "<script language='javascript'>alert('Invalid username and password.')</script>";
}
else
{
echo "Please contact the site administrator.<br/>Error: Duplicates exists";
echo "<script language='javascript'>alert('Plese Contact Authors..')</script>";
}
}
else
{
//do nothing.
}
}
?>
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.