PHP code not working....none of it!!
Posted: Sun Mar 01, 2009 10:49 am
Hi,
I'm trying to learn php and MySQL using the book 'Head First PHP & MySQL' (great book!!) but im having trouble with a registration form (where a user registers at the site). The book comes with source code which I've uploaded to my server to test and works fine, but when i use the code for my site none of it works, nothing (the html code before the php works but thats it...none of the php works). Any ideas...this is killing me. I have a feeling its something small thats stopping it but i've been trying to work this out since last saturday!!! Any ideas?
I'm trying to learn php and MySQL using the book 'Head First PHP & MySQL' (great book!!) but im having trouble with a registration form (where a user registers at the site). The book comes with source code which I've uploaded to my server to test and works fine, but when i use the code for my site none of it works, nothing (the html code before the php works but thats it...none of the php works). Any ideas...this is killing me. I have a feeling its something small thats stopping it but i've been trying to work this out since last saturday!!! Any ideas?
Code: Select all
<?php
//XMLXSL Transformation class
require_once('../includes/MM_XSLTransform/MM_XSLTransform.class.php');
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:spry="http://ns.adobe.com/spry">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>ESL Groups - Register With Us</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="description" content="Studio7designs - Professional Photography and Graphic Designs, Victoria BC Canada" />
<meta name="keywords" content="Studio7designs" />
<meta name="author" content="Aran / Original design: Aran Down - http://www.studio7designs.com" />
<link rel="stylesheet" type="text/css" href="contentCSS/style.css" />
<link rel="shortcut icon" href="../favicon/favicon.png" />
<link rel="stylesheet" type="text/css" media="all" href="contentCSS/bannerHills.css" />
<link rel="stylesheet" type="text/css" media="all" href="contentCSS/registerCSS.css" />
<style type="text/css">
<!--
.style1 {
color: #669966;
letter-spacing: 1px;
border-bottom: 1px solid #ffb400;
}
</style>
</head>
<body>
<?php include('contentIncludes/header.php') ?>
<div id="wrapper-content">
<div id="wrapper-menu-page">
<div id="menu-page">
<h3> </h3>
<h3>learn more...</h3>
<ul>
<li><a href="why_elearning.php">Why online learning?</a></li>
<li><a href="why_ESL.php">Why ESL Groups?</a></li>
<li><a href="Whats_great_video.php">Whats so special about <br />the video lessons?</a></li>
</ul>
<h3>Free Lessons</h3>
<ul>
<li><a href="freeBasic.php">The Basics</a></li>
<li><a href="freeIntermediate.php">Intermediate</a></li>
<li><a href="freeAdvanced.php">Advanced</a></li>
</ul>
<h3>Start Learning</h3>
<ul>
<li><a href="fullLibrary.php">See all our lessons</a></li>
<li><a href="lessonLibrary.php">Lessons arranged by <br />difficulty</a></li>
</ul>
<p> </p>
</div><!--menu-page-->
</div>
<div id="content">
<h2 class="style1">Register with ESL Groups</h2>
<p>Join ESL Groups and learn practical English </p>
<h2 class="upperCaseHeader">please enter your details</h2><p>
</p>
<!---------------------------------------------------------------------THIS IS THE REGISTRATION CODE BELOW------>
<?php
require_once('scripts/appvars.php');
require_once('scripts/connectvars.php');
// Connect to the database
$dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
if (isset($_POST['submit'])) {
// Grab the profile data from the POST
$username = mysqli_real_escape_string($dbc, trim($_POST['username']));
$password1 = mysqli_real_escape_string($dbc, trim($_POST['password1']));
$password2 = mysqli_real_escape_string($dbc, trim($_POST['password2']));
if (!empty($username) && !empty($password1) && !empty($password2) && ($password1 == $password2)) {
// Make sure someone isn't already registered using this username
$query = "SELECT * FROM myTable WHERE username = '$username'";
$data = mysqli_query($dbc, $query);
if (mysqli_num_rows($data) == 0) {
// The username is unique, so insert the data into the database
$query = "INSERT INTO myTable (username, password, join_date) VALUES ('$username', SHA('$password1'), NOW())";
mysqli_query($dbc, $query);
// Confirm success with the user
echo '<p>Your new account has been successfully created. You\'re now ready to <a href="login.php">log in</a>.</p>';
mysqli_close($dbc);
exit();
}
else {
// An account already exists for this username, so display an error message
echo '<p class="error">An account already exists for this username. Please use a different address.</p>';
$username = "";
}
}
else {
echo '<p class="error">You must enter all of the sign-up data, including the desired password twice.</p>';
}
}
mysqli_close($dbc);
?>
<p>Please enter your username and desired password to sign up to Mismatch.</p>
<form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<fieldset>
<legend>Registration Info</legend>
<label for="username">Username:</label>
<input type="text" id="username" name="username" value="<?php if (!empty($username)) echo $username; ?>" /><br />
<label for="password1">Password:</label>
<input type="password" id="password1" name="password1" /><br />
<label for="password2">Password (retype):</label>
<input type="password" id="password2" name="password2" /><br />
</fieldset>
<input type="submit" value="Sign Up" name="submit" />
</form>
<br />
or you can email us at <a href="mailto:info@eslGroups.com">info@ESLGroups.com</a>.
</div>
</div>
</div>
<?php include('contentIncludes/footer.php'); ?>
</body>
</html>