I've made a basic user management system using php and mysql. originally i just had a full index.html page with a form and the rest of the pages contained no graphics and only scripts.
The index page had the original form that posted user details over, designed in photoshop i used a section in the center of the page to hold the content, the div tag with overflow set to auto so that i could control the size of the page.
I thought it would be a simple matter of converting this page into two functions, one up to and including the opening div tag
eg: <div> , the other one beginning with the closing of the div </div> and the rest of the page. these functions placed either side of the other php scripts would place the content produced by the other scripts inside the content of the div, and overflow if necessary. or so i hoped.
For some reason when these functions are included in the other php scripts the second of the two functions is not found or recognised. i dont know if this could be something to do with the php script i have used, i'm quite new to php so i'm not too sure. When the functions are placed next to each other, before any other php is executed the page displays perfectly with the other code underneath.
when the functions are inside the text however it will not work. i have checked the html it produces and it doesnt show anything from where the div should be closed onwards other than the content that the php script has added.
this is the script that i post to from my index page:
<?php
require ('functions.php');
include 'db.php';
// Defines posted fields into simple variables
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email_address = $_POST['email_address'];
$username = $_POST['username'];
$info = $_POST['info'];
//FUNCTION FOR TOP SECTION OF PAGE - EVERYTHING TO THE CLOSING OF THE OPENING DIV TAG
pagetop();
/* Let's strip some slashes in case the user entered
any escaped characters. */
$first_name = stripslashes($first_name);
$last_name = stripslashes($last_name);
$email_address = stripslashes($email_address);
$username = stripslashes($username);
$info = stripslashes($info);
//error check the form data
if ((!$first_name) || (!$last_name) || (!$email_address) || (!$username))
{
echo 'You did not enter the required information <br />';
if (!$first_name)
{
echo 'First Name is a required field, please fill it our <br />';
}
if (!$last_name)
{
echo 'Last Name is a required field, please fill it out <br />';
}
if (!$email_address)
{
echo 'Email address is a required field, please fill it out <br />';
}
if (!$username)
{
echo 'Username is a required field, sort it. <br />';
}
include 'join_form.html';// Show the form again!
/* End the error checking and if everything is ok, we'll move on to
creating the user account */
exit();
}
/* Let's do some checking and ensure that the user's email address or username
does not exist in the database */
$sql_email_check = mysql_query("select email_address from users where email_address = '$email_address'");
$sql_username_check = mysql_query ("select username from users where username = '$username'");
$email_check = mysql_num_rows($sql_email_check);
$username_check = mysql_num_rows($sql_username_check);
if (($email_check >0) || ($username_check >0))
{
echo 'Please fix the following errors: <br />';
if ($email_check >0)
{
echo 'That email address is already in use, please choose another';
unset ($email_address);
}
if ($username_check >0)
{
echo 'That username is already in use, please choose another';
unset ($username);
}
include 'join_form.html';
exit();
}
//FUNCTION FOR THE REST OF THE PAGE: FROM THE CLOSING OF THE DIV TO THE END
pagebottom();
/* Everything has passed both error checks that we have done.
It's time to create the account! */
/* Random Password generator.
[url]http://www.phpfreaks.com/quickcode/Random_Password_Generator/56.php[/url]
We'll generate a random password for the
user and encrypt it, email it and then enter it into the db.
*/
function makeRandomPassword() {
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
$i = 0;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($salt, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
$random_password = makeRandomPassword();
$db_password = md5($random_password);
// Enter information about the user into the Database.
$info2 = htmlspecialchars($info);
$sql = mysql_query("INSERT INTO users (first_name, last_name,
email_address, username, password, info, signup_date)
VALUES('$first_name', '$last_name', '$email_address',
'$username', '$db_password', '$info2', now())")
or die (mysql_error());
if(!$sql){
echo 'There has been an error creating your account. Please contact the webmaster.';
} else {
$userid = mysql_insert_id();
// Let's mail the user!
$subject = "Your Membership at MyWebsite!";
$message = "Dear $first_name $last_name,
Thank you for registering at our website, [url]http://www.mydomain.com[/url]!
You are two steps away from logging in and accessing our exclusive members area.
To activate your membership,
please click here: [url]http://localhost/public/suv/activate.php?id=[/url]$userid&code=$db_password
Once you activate your memebership, you will be able to login
with the following information:
Username: $username
Password: $random_password
Thanks!
The Webmaster
This is an automated response, please do not reply!";
mail($email_address, $subject, $message,
"From: MyDomain Webmaster<admin@mydomain.com>\n
X-Mailer: PHP/" . phpversion());
echo 'Your membership information has been mailed to your email address!
Please check it and follow the directions!';
}
?>
Thanks a lot for anyone that takes the time to read, understand and help.