I am having a bit of trouble with following a tutorial at http://www.upgradetheweb.com/2007/07/31/building-your-own-myspacecom-with-phppart-i-introduction/ . It doesn't really explain where to put the code or anything, so there is the possibility that everything is completely wrong. What the problem is, is that when I log in, the page just refreshes (it sort of works, cos when i just type random letters into the box, it says that it doesn't exist). And I cant for the love of god get the edit function to work. I have the DbConnector.php and Dbvars.php working. Here is the code for the other pages:
signup.php
login.php
member.php
any help would be greatly appreciated.
signup.php
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>untitled</title>
</head>
<body>
<div id="container">
<div id="header">
<h1>jpex</h1>
<h2>sign up</h2>
</div><!-- End Header -->
<div id="contentcontainer">
<div id="sidebar">
</div><!-- End Sidebar -->
<div id="content">
<?php
// Check if the form has been submitted
if(isset($_GET["submit"]))
{
if(isset($_POST["username"]) && isset($_POST["password"]))
{
//Username or password is not blank
if($_POST["username"]!="" && $_POST["password"]!="")
{ // Everything is ok add the user to the database
// Connect to the database
require_once("classes/DbConnector.php"); // Include the database class
$db = new DbConnector(); // Create an instance of the database class
$db->connect(); // Connect to the database
$query = "SELECT * FROM members WHERE username='".$_POST["username"]."'";
$result = $db->query($query);
$result = mysql_num_rows($result);
if($result!="0")
echo "Username already exists!";
else
{
// Create a query that inserts the data from the form to the database
$query = "INSERT INTO members(username,password) VALUES('".$_POST["username"]."','".$_POST["password"]."')";
$result = $db->query($query);
echo "Signed up succesfully you can now <a href=\"login.php\">log in</a>";
}
}
else
{
echo "Error: No username or password supplied, try again.";
}
}
else
echo "Error: please fill in the <a href=\"signup.php\">signup form</a>";
}
?>
<form action="signup.php?submit" method='POST'>
<fieldset>
<legend>Login Details</legend>
<p>Username: <input name='username' size='25' maxlength='25' /></p>
<p>Password: <input name='password' size='25' maxlength='25' /></p>
<p><button type='submit'>Submit</button></p>
</fieldset>
</form>
</div><!-- End Content -->
</div><!-- End Content Container -->
</div><!-- End Container -->
</body>
</html>
login.php
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>untitled</title>
</head>
<body>
<div id="container">
<div id="header">
<h1>jpex</h1>
<h2>log in</h2>
</div><!-- End Header -->
<div id="contentcontainer">
<div id="sidebar">
</div><!-- End Sidebar -->
<div id="content">
<?php
// login.php
session_start();
if(isset($_GET["submit"]))
{
login($_POST["username"],$_POST["password"]);
}
function login($username,$password)
{
require_once("classes/DbConnector.php");
$db = new DbConnector();
$db->connect();
$query = "SELECT * FROM members WHERE username='$username' AND password='$password'";
$result = $db->query($query);
$result = mysql_num_rows($result); // Does the row exists?
if($result!="0"){
// authenication correct lets login
$_SESSION["password"] = $password;;
$_SESSION["username"] = $username;
header("Location: member.php?id=$username");
}
else
{
echo "Wrong username or password. Please try again!";
}
}
?>
<form action="login.php?submit" method='POST'>
<fieldset>
<legend>Login Details</legend>
<p>Username: <input name='username' size='25' maxlength='25' /></p>
<p>Password: <input name='password' size='25' maxlength='25' /></p>
<p><button type='submit'>Login</button></p>
</fieldset>
</form>
</div><!-- End Content -->
</div><!-- End Content Container -->
</div><!-- End Container -->
</body>
</html>
member.php
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>untitled</title>
</head>
<body>
<div id="container">
<div id="header">
<h1>jpex</h1>
<h2>profile</h2>
</div><!-- End Header -->
<div id="contentcontainer">
<div id="sidebar">
</div><!-- End Sidebar -->
<div id="content">
<?php
// members.php
if(isset($_GET["id"]))
{
// Check if user exists in the database
$member = $_GET["id"];
require_once("classes/DbConnector.php");
$db = new DbConnector();
$db->connect();
$query = "SELECT * FROM members WHERE username='$member'";
$result = $db->query($query);
$exists = mysql_num_rows($result); // Does the row exists?
if($exists !="0"){ // Presentation exists so display it
$rows = $db->fetchArray($result); // Get the profile from database
echo $rows["presentation"]."<br/><br/>";
//TODO: Display guestbook here
}
else
{
echo "That member does not exist";
}
}
?>
<?php
if(isset($_GET["edit"])) // Edit profile
{
// First lets make sure the user is logged in
if(session_is_registered("username") && session_is_registered ("password") && $_SESSION["username"] == $_GET["edit"])
{
if(isset($_GET["update"]))
{
require_once("classes/DbConnector.php");
$member = $_GET["edit"];
$db = new DbConnector();
$db->connect();
$presentation = $_POST["presentation"];
$query = "UPDATE members SET presentation='$presentation' WHERE username='$member'";
$result = $db->query($query);
echo "Profile updated!";
}
else
{ // Display edit box
require_once("classes/DbConnector.php");
$member = $_GET["edit"];
$db = new DbConnector();
$db->connect();
$query = "SELECT * FROM members WHERE username='$member'";
$result = $db->query($query);
$rows = $db->fetchArray($result);
echo "<b>Edit your profile</b><br/>\n
<form action=\"member.php?edit=".$_GET["edit"]."&update\" method='POST'>
<textarea name='presentation' rows='10' cols='80' align='left'>"
.$rows["presentation"].
"</textarea><br/>
<input type='submit' value='Update' name='submit' />
</form>
";
}
}
}
?>
<form action="member.php?edit" method="get">
<p><input type="text" name="edit" /></p>
</form>
</div><!-- End Content -->
</div><!-- End Content Container -->
</div><!-- End Container -->
</body>
</html>
any help would be greatly appreciated.