PHP help
well, this is kinda embarrassing since I'm working on a college project, and right now I'm stuck at the registration page. Here's the code and the error:
Registration Page
<html><head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>Online Music Player Registration Site</title><style type="text/css">
.prompt{color: blue; font-family:Arial; font-size:medium}
</style></head>
<body>
<p><big style="font-weight: bold;">
REGISTER TO THIS SITE</big><br>
</p>
<p><br>
Register to this site in order to gain the full benefits this site offers.<br>
</p>
<form method="post" action="form.php">
<table width="100%" border="0" cellpadding="0" cellspacing="1">
<tr>
<td width="10%" valign="top">Username</td>
<td width="48%"><input type="text" name="username" /> <br /> </font></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password" /><br>
</tr>
<tr>
<td colspan="2"><hr size="1" /></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email" /> <br/><font color="red" size="2">(E-mail is important so that your registration can be verified) </font></td>
</tr>
<tr>
<td><p>Type of user</p></td>
<td>
<input type="radio" name="user" value= "normal user" /> Normal user
<input type="radio" name="user" value= "musician" /> Musician
</td>
</tr>
<tr>
<td><p>Gender</p></td>
<td>
<input type="radio" name="gender" value="female" />Female
<input type="radio" name="gender" value="male" /> Male </td>
</tr>
<tr>
<td><p> </p></td>
<td><p><br />
<input type="submit" name="Submit" value="Register" class="funcbutton" />
</p></td>
</tr>
</table>
<input type="hidden" name="ref" value="" />
</form>
form.php
$username = htmlspecialchars($_POST['username']);
if (preg_match("/\s/",$text))
{
die("do not use spaces, tabs or newlines in your username");
}
$email = htmlspecialchars($_POST['email']);
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email))
{
die("Invalid E-mail address");
}
$Password = htmlspecialchars($_POST['Password']);
if (preg_match("/\s/",$text))
{
die("do not use spaces, tabs or newlines in your password");
}
?>
<html>
<body>
Your name is: <?php echo $username; ?><br />
Your e-mail: <?php echo $email; ?><br />
<br />
</body>
</html>
<?php
function check_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
die($problem);
}
return $data;
}
function show_error($anyError)
{
?>
<html>
<body>
<b>Please correct the following errors:</b><br />
<?php echo $myError; ?>
</body>
</html>
<?php
exit();
}
?>```
The message I got was:
> Notice: Undefined variable: text in C:\wamp\www\mplayer\form.php on line 3
Notice: Undefined index: Password in C:\wamp\www\mplayer\form.php on line 13
Notice: Undefined variable: text in C:\wamp\www\mplayer\form.php on line 14
Your name is: fuser
Your e-mail: hadri90@gmail.com
and another function I was working on is a date of birth selection option, since my supervisor suggested that I include it in my page to filter out users who are below 15 years old.
```markup
<html xmlns="http://www.w3.org/1999/xhtml">
<form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?> ">
<select name="day"><?php
for ($i = 1; $i <= 31; i++) {
echo "<option value=\"$i\">$i</option>\n";
}
?></select>
<select name="month"><?php
for ($i = 1; $i <= 12; i++) {
$monthname = date('F', mktime(12, 0, 0, $i, 1, 1930));
echo "<option value=\"$i\">$monthname</option";
}
?></select>
<select name="year"><?php
for ($i = 1930; $i = 2010; i++) {
echo "<option value=\"$i\">$i</option>";
}
?></select>
</form>
</html>
the message I got for this one is:
Parse error: parse error, expecting `')'' in C:\wamp\www\dateselection.php on line 4
and another thing, does anyone know how I can implement the date selection code into the registration form?
I'm not sure if you're trying to do something odd here, but might you want to replace $text with $username and whatnot to actually test them? Looks like you might've copied template code and forgotten to replace the vars
$username = htmlspecialchars($_POST['username']);
if (preg_match("/\s/",$text))
{
die("do not use spaces, tabs or newlines in your username");
}
ok, I've fixed the errors in both code, while the first one kind-of works, (I still haven't made the databases yet), it seems fine.
I still have a problem on the birth selection code, though. It runs without any errors, the drop-down boxes doesn't even show any numbers (day, month, year) for me to choose from. any idea why this happens?
the amended code is:
<form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?> ">
<select name="day"><?php
for ($i = 1; $i <= 31; $i++) {
echo "<option value=\"$i\">$i</option>\n";
}
?></select>
<select name="month"><?php
for ($i = 1; $i <= 12; $i++) {
$monthname = date('F', mktime(12, 0, 0, $i, 1, 1971));
echo "<option value=\"$i\">$monthname</option>";
}
?></select>
<select name="year"><?php
for ($i = 1971; $i <= 2010; $i++) {
echo "<option value=\"$i\">$i</option>";
}
?></select>
</form>
</html>
There were a few minor things missing. This code works for me.
<form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?> ">
<select name="day"><?php
for ($i = 1; $i <= 31; $i++) {
echo "<option value=\"$i\">$i</option>\n";
}
?></select>
<select name="month"><?php
for ($i = 1; $i <= 12; $i++) {
$monthname = date('F', mktime(12, 0, 0, $i, 1, 1930));
echo "<option value=\"$i\">$monthname</option>";
}
?></select>
<select name="year"><?php
for ($i = 1971; $i <= 2010; $i++) {
echo "<option value=\"$i\">$i</option>";
}
?></select>
</form>
</html>```
EDIT: Looks the same as yours. Must be your php install or something.
Another thing you may want to look at is the number of days in the month. You have it loop through and set the days to 31. I want to be born on February 31st!
You may want to have the month and year selection first. this will then reflect the day loop. just remember the months that have 30 days, the ones that have 31 days, and the one that has 28 or 29…This will help you make this form a lot better.
well, I've been trying to figure out how to do that for the whole day, but so far I haven't been able to gain any results.
also, I'm still stuck trying to figure out how to subtract from the selected date and the date the user signed up, and then figure out if the user it at least is 15 years old (a restriction placed by my project supervisor), and this also results in me hitting a wall most of the time.
fuser wrote: also, I'm still stuck trying to figure out how to subtract from the selected date and the date the user signed up, and then figure out if the user it at least is 15 years old (a restriction placed by my project supervisor), and this also results in me hitting a wall most of the time. Here's one way you can go about doing it: http://www.daniweb.com/forums/thread74794.html# Found by googling "age verification script".
And here's the method I mentioned to you in IM last night: http://www.phpf1.com/tutorial/php-date-difference.html Found by googling "php date difference".
well, thanks for the links ynori, but most of the tutorials I stumble upon is usually based on a set date, my problem now is trying to figure out how to make it work from the date selected through date selection menu.
I know I'm doing it wrong, I know the concept, but I'm still stuck trying to implement it into code.
I''ve been at it all morning, now I'm beat. Maybe I'll have better luck tomorrow.
fuser wrote: well, thanks for the links ynori, but most of the tutorials I stumble upon is usually based on a set date, my problem now is trying to figure out how to make it work from the date selected through date selection menu.
This should work:
markup$date = mktime(0,0,0,$_POST['month'],$_POST['day'],$_POST['year']);
Just have your code check to see that the post variables are set (meaning that the user clicked submit), and then make the date object.
I would suggest something like this (crappy code threw together in 1 minute):
if( $month == 6 || $month == 8 || $month == 9 || $month == 11 )
{
$maxday = 30;
}
elseif( $month == 2 )
{
if( $year % 4 )
{
$maxday = 28;
}
else
}
$maxday = 29;
}
}
else
{
$maxday = 31;
}
Please do not mind the crap code, but you get the gist.
AldarHawk wrote: I would suggest something like this (crappy code threw together in 1 minute): code Please do not mind the crap code, but you get the gist.Might go wrong in February 2100 though, as that's not a leap year. Y2.1K Bug? :) (Yes you did say the code was crappy, but that doesn't have to mean it's also incorrect. :P )
Here is some pseudocode from wikipedia on the subject of leap years that could easily be included in your code.
if year modulo 400 is 0
then is_leap_year
else if year modulo 100 is 0
then not_leap_year
else if year modulo 4 is 0
then is_leap_year
else
not_leap_year
Also, the reason nothing major happened with y2k is that many programmers were hired specifically to make sure that their companies applications were y2k compliant and would not malfunction. Years of work went into making sure that nothing happened.
I managed to figure out how to do it, but the problem now is that every time I try to run it it immediately overwhelms my computer and crashes it, making it necessary to reboot.
here's the code:
if (isset($_POST['month']) && is_numeric($_POST['month']) && ((int)$_POST['month'] >= 1 && (int)$_POST['month'] <= 12))
{
$month = (int)$_POST['month'];
}
else
{
$month = date('n');
}
if (isset($_POST['year']) && is_numeric($_POST['year']) && ((int)$_POST['year'] >= 1971 && (int)$_POST['year'] <= 2010))
{
$year = (int)$_POST['year'];
} else {
$year = date('Y');
}
?>
<form method="post" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']); ?> ">
<select name="day"><?php
$maxdays = date('t', mktime(12, 0, 0, $month, 1, $year));
for ($i = 1; $i <= $maxdays; $i++) {
if (isset($_POST['day']) && $_POST['day'] == $i)
{
$sel = 'selected';
}
elseif ($i == date('j'))
{
$sel = 'selected';
}
else
{
$sel = '';
}
echo "<option value=\"$i\"$sel>$i</option\>\n";
}€
?></select>
<select name="month" onchange="this.form.submit();"><?php
for ($i = 1; $i <= 12; $i++) {
if ($month == $i) {
$sel = ' selected';
} else {
$sel = '';
}
$monthname = date('F', mktime(12, 0, 0, $i, 1, 2005));
echo "<option value=\"$i\"$sel>$monthname</option>\n";
}
?></select>
<select name="year" onchange="this.form.submit();"><?php
for ($i = 1971; i <= 2010; $i++) {
if ($year == $i) {
$sel = ' selected';
} else {
$sel = '';
}
echo "<option value=\"$i\"$sel>$i</option>\n";
}
?></select>
now can anyone figure out what's wrong, or does this happen only to me?
yeah, after I posted it, only then did I check the script again only did I noticed what I did wrong, and it worked fine. should've checked first before posting it at the forums.
I have several questions. Firstly, I'm still stuck with the age limit restriction, and I've already figured out how to make one, except that I have to store the birthday in the array, and that I can't make it include leap years.
my plan is to make the date selected by the user being stored into an array, and from there subtract it with the date of registration, and that he has to be at least 13.
here's the code I found from PHP Builder:
<?php
function validateUserAge($bday, $min = 13)
{
list($day, $month, $year) = explode('-', $bday);
$minYear = date('Y') - $min;
if ($year >= $minYear)
{
$age = calculateAge($bday);
if ($age < $min)
return false;
}
return true;
}
?>
<?php
function calculateAge($bday)
{
$birth = strtotime($bday);
$ageStamp = time() - $birth;
$year = 60 * 60 * 24 * 365; // not accounting leap years
return floor($ageStamp / $year);
}
?>
<?php
$minAge = 13;
$bdays = array("10-09-1990");
foreach ($bdays as $bday)
{
if(validateUserAge($bday, $minAge))
echo "user is old enough to enter<br />\n";
else
echo "you have to be at least 13 to enter";
}
?>
[addedon]February 2, 2010, 1:43 pm[/addedon]the second problem is that I've also made another PHP file that basically adds data into the database I've created, but it seems I've also hit a wall with this one.
<?php
$connect = mysql_connect("localhost", "fuser", "projectpass") or die ("connection could not be established.");
mysql_select_db("mp3site");
//insert data into musician table
$insert = "INSERT INTO musician(musician_id, musician_type, musician_name, musician_genre)" .
"VALUES (1, 1, 'Carburetor Dung', 1), " .
"(2, 1, 'Instake', 2), " .
"(3, 1, 'Second Combat', 3), " .
"(4, 2, 'T.I.M.', 1), " .
"(5, 1, 'Sarjan Hassan', 4), " .
"(6, 1, 'LAW', 5), ";
$results = mysql_query($insert) or die (mysql_error());
//insert data into musician type table
$type = "INSERT INTO musiciantype(musiciantype_id, musiciantype_type) " .
" VALUES (1, 'Band'), " .
" (2, 'Solo artist') " .
$results = mysql_query($type) or die (mysql_error());
//insert data into genre table
$type = "INSERT INTO genre (genre_id, genre_type) " .
" VALUES (1, 'Punk Rock'), " .
" (2, 'Rock'), " .
" (3, 'Hardcore') " .
" (4, 'Metal') " .
" (5, 'Indie') " .
$results = mysql_query($type) or die (mysql_error());
echo "Data inserted ";
?>
the error I got was:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
but what was there in line 1? This problem happens on both WAMP and XAMPP, so do I have to add the data into the site through PHPMyAdmin?
okay, you need to make sure you open the connection to the database.
$connection = mysql_connect( $host,$user,$password ) or die( "Cannot connect to DB: ".mysql_error() ); $data = mysql_select_db( $dbname, $connection );
you forgot to tell SQL that you NEED the database connection. Try that and let me know.
AldarHawk wrote: okay, you need to make sure you open the connection to the database.
$connection = mysql_connect( $host,$user,$password ) or die( "Cannot connect to DB: ".mysql_error() ); $data = mysql_select_db( $dbname, $connection );
you forgot to tell SQL that you NEED the database connection. Try that and let me know. … He wouldn't be getting a SQL error if the connection wasn't open. The second argument to select_db (the connection reference) is optional. He got an "error in his SQL statement" because he has an error in his SQL statement:
fuser wrote: $insert = "INSERT INTO musician(musician_id, musician_type, musician_name, musician_genre)" . "VALUES (1, 1, 'Carburetor Dung', 1), " . "(2, 1, 'Instake', 2), " . "(3, 1, 'Second Combat', 3), " . "(4, 2, 'T.I.M.', 1), " . "(5, 1, 'Sarjan Hassan', 4), " . "(6, 1, 'LAW', 5), ";
You're missing a space between ) and VALUES, and you have some sort of lingering comma at the end of the SQL statement.
I know this is hard to believe, but a web server will often tell you what's wrong if:
- You allow it to by showing errors.
- You pay attention to the error messages it shows you.
ok, after much thinking last night I've decided to ditch the dob code since it's causing me unncessary trouble. Right now I'm working on the registration page, and this error simply stumped me.
I assume there's an error in my syntax, but I can't seem to figure it out.
Registration Page:
<html><head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>Online Music Player Registration Site</title><style type="text/css">
.prompt{color: blue; font-family:Arial; font-size:medium}
</style></head>
<body>
<p><big style="font-weight: bold;">
REGISTER TO THIS SITE</big><br>
</p>
<p><br>
Register to this site in order to gain the full benefits this site offers.<br>
</p>
<form method="post" action="form.php">
<table width="100%" border="0" cellpadding="0" cellspacing="1">
<tr>
<td width="10%" valign="top">Username</td>
<td width="48%"><input type="text" name="username" /> <br /> </font></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password" /><br>
</tr>
<tr>
<td colspan="2"><hr size="1" /></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="email" /> <br/><font color="red" size="2">(E-mail is important so that your registration can be verified) </font></td>
</tr>
<tr>
<td><p>Type of user</p></td>
<td>
<input type="radio" name="user" value= "normal user" /> Normal user
<input type="radio" name="user" value= "musician" /> Musician
</td>
</tr>
<tr>
<td><p>Gender</p></td>
<td>
<input type="radio" name="gender" value="female" />Female
<input type="radio" name="gender" value="male" /> Male </td>
</tr>
<tr>
<td><p>
<input type="submit" name="Submit" id="Submit" value="Submit">
<br />
</p></td>
</tr>
</table>
<input type="hidden" name="ref" value="" />
</form>
[edit] form.php
<?php
$username = htmlspecialchars($_POST['user_name']);
if (preg_match("/\s/",$username))
{
die("do not use spaces, tabs or newlines in your username");
}
$email = htmlspecialchars($_POST['user_email']);
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email))
{
die("Invalid E-mail address");
}
$Password = htmlspecialchars($_POST['user_password']);
if (preg_match("/\s/",$Password))
{
die("do not use spaces, tabs or newlines in your password");
}
?>
<html>
<body>
Your name is: <?php echo $username; ?><br />
Your password is: <?php echo $Password; ?><br />
Your e-mail: <?= $email ?><br />
<?php echo "Please remember your details for future registration"; ?><br />
<br />
</body>
</html>
<?php
function check_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
die($problem);
}
return $data;
}
function show_error($anyError)
{
?>
<html>
<body>
<b>Please correct the following errors:</b><br />
<?php echo $myError; ?>
</body>
</html>
<?php
exit();
}
?>
<?php
$connect = mysql_connect("localhost", "root") or die ("connection could not be established.");
mysql_select_db("users");
$insert = "INSERT INTO user(user_name, user_password, user_email, user_type, user_gender)" .
"VALUES ('{$_POST['user_name']}', '{$_POST['password']}', '{$_POST['user_email']}', '{$_POST['user_type']}', '{$_POST['user_gender']}')";
$results = mysql_query($insert) or die (mysql_error());
?>
[/edit]
create user table:
createuser.php
$connect = mysql_connect("localhost", "fuser", "projectpass") or die("Could not establish connection");
$create = mysql_query("CREATE DATABASE IF NOT EXISTS users") or die (mysql_error());
mysql_select_db("users");
$user = "CREATE TABLE user(user_id int(15) NOT NULL auto_increment,
user_name varchar(255) NOT NULL,
user_password varchar(255) NOT NULL,
user_email varchar(255) NOT NULL,
user_type varchar(255) NOT NULL,
user_gender varchar(255) NOT NULL,
PRIMARY KEY (user_id),
KEY user_type(user_type, user_gender))";
$results = mysql_query($user) or die (mysql_error());
$usertype = "CREATE TABLE usertype
(usertype_id tinyint(2) NOT NULL auto_increment,
usertype_type varchar(255) NOT NULL,
PRIMARY KEY(usertype_id))";
$results = mysql_query($usertype) or die (mysql_error());
$gender = "CREATE TABLE gender
(gender_id int(15) NOT NULL auto_increment,
gender_type varchar(255) NOT NULL,
PRIMARY KEY(gender_id))";
$results = mysql_query($gender) or die (mysql_error());
echo "Database Created";
?>```
and the user table:
userdata.php
```markup<?php
$connect = mysql_connect("localhost", "fuser", "projectpass") or die("connection could not be established");
mysql_select_db("users");
$insert = "INSERT INTO user(user_id, user_name, user_password, user_email, user_type, user_gender)" .
"VALUES (1, 'User A', 'abcdef', 'zzyx@mail.com', 1, 1), " .
"(2, 'User B', 'abc123', 'mail@mail.com', 1, 2), " .
"(3, 'User C', 'zxcvbn', '1234@mail.com', 2, 1), " .
"(4, 'User D', 'qwerty', 'abcd@mail.com', 2, 2), " .
"(5, 'User E', '123456', 'xkcd@mail.com', 3, 2) " ;
$results = mysql_query($insert) or die (mysql_error());
$type = "INSERT INTO usertype(usertype_id, usertype_type) " .
" VALUES (1, 'Normal User'), " .
" (2, 'Musician'), " .
" (3, 'Administrator') ";
$results = mysql_query($type) or die (mysql_error());
$gender = "INSERT INTO gender(gender_id, gender_type) " .
" VALUES (1, 'Female'), " .
" (2, 'Male') ";
$results = mysql_query($gender) or die (mysql_error());
?>```
I should note that my login page works fine though..
login.php
```markup<html>
<head>
<title>Login Page</title>
<title>Online Music Player Login Page</title><style type="text/css">
.prompt{color: blue; font-family:Arial; font-size:medium}
</style></head>
<form method="post" action="checkLogin.php">
<table width="100%" border="0" cellpadding="0" cellspacing="1">
<tr>
<td width="10%" valign="top">Username</td>
<td width="48%"><input type="text" name="username" /> <br /> </font></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password" /><br>
</tr>
<tr>
<td colspan="2"><hr size="1" /></td>
</tr>
<tr>
<td><p>
<input type="submit" name="Submit" id="Submit" value="Submit">
<br />
</p></td>
</tr>
</table>
<input type="hidden" name="ref" value="" />
</form>
</html>```
checkLogin.php
```markup<?php
// checkLogin.php
session_start(); // Start a new session
require('conn.php'); // Holds all of our database connection information
// Get the data passed from the form
$username = $_POST['username'];
$password = $_POST['password'];
// Do some basic sanitizing
$username = stripslashes($username);
$password = stripslashes($password);
$sql = "select * from user where user_name = '$username' and user_password = '$password'";
$result = mysql_query($sql) or die ( mysql_error() );
$count = 0;
while ($line = mysql_fetch_assoc($result)) {
$count++;
}
if ($count == 1) {
$_SESSION['loggedIn'] = "true";
echo "welcome";
} else {
$_SESSION['loggedIn'] = "false";
echo "sorry, try again.";
}
?>```
the funny thing is that the error now is that all the e-mail addresses I've inputted into the e-mail field are considered invalid.. o_O
the previous post was a bit too long, so I hope no one is offended by the fact I've decided to make a new post.
I think I've fixed the form code now, so it now looks like this:
$username = htmlspecialchars($_POST['user_name']);
if (preg_match("/\s/",$username))
{
die("do not use spaces, tabs or newlines in your username");
}
$email = htmlspecialchars($_POST['user_email']);
if (preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email))
{
die("Invalid E-mail address");
}
$Password = htmlspecialchars($_POST['user_password']);
if (preg_match("/\s/",$Password))
{
die("do not use spaces, tabs or newlines in your password");
}
?>
<html>
<body>
Your name is: <?php echo $username; ?><br />
Your password is: <?php echo $Password; ?><br />
Your e-mail: <?= $email ?><br />
<?php echo "Please remember your details for future registration"; ?><br />
<br />
</body>
</html>
<?php
function check_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
die($problem);
}
return $data;
}
function show_error($anyError)
{
?>
<html>
<body>
<b>Please correct the following errors:</b><br />
<?php echo $myError; ?>
</body>
</html>
<?php
exit();
}
?>
<?php
$connect = mysql_connect("localhost", "root") or die ("connection could not be established.");
mysql_select_db("users");
$insert = "INSERT INTO user(user_name, user_password, user_email, user_type, user_gender)" .
"VALUES ('{$_POST['user_name']}', '{$_POST['password']}', '{$_POST['user_email']}', '{$_POST['user_type']}', '{$_POST['user_gender']}')";
$results = mysql_query($insert) or die (mysql_error());
?>
well, the issue now is:
results in:
I'm pretty sure I've screwed the code up somewhere, just not sure which one.
Does this part output the right info:
<body>
Your name is: <?php echo $username; ?><br />
Your password is: <?php echo $Password; ?><br />
Your e-mail: <?= $email ?><br />
<?php echo "Please remember your details for future registration"; ?><br />
<br />
</body>
</html>```
That'll tell if it's the data entry that's the problem or the part putting the data into the table.
well, now the database recognizes the user name, email and password, but now it doesn't recognize the user type and the user gender. must've been a mistake I made in either code..
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html><head>
<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type"><title>Online Music Player Registration Site</title><style type="text/css">
.prompt{color: blue; font-family:Arial; font-size:medium}
</style></head>
<body>
<p><big style="font-weight: bold;">
REGISTER TO THIS SITE</big><br>
</p>
<p><br>
Register to this site in order to gain the full benefits this site offers.<br>
</p>
<form method="post" action="form.php">
<table width="100%" border="0" cellpadding="0" cellspacing="1">
<tr>
<td width="10%" valign="top">Username</td>
<td width="48%"><input type="text" name="user_name" /> <br /> </font></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="user_password" /><br>
</tr>
<tr>
<td colspan="2"><hr size="1" /></td>
</tr>
<tr>
<td>Email</td>
<td><input type="text" name="user_email" /> <br/><font color="red" size="2">(E-mail is important so that your registration can be verified) </font></td>
</tr>
<tr>
<td><p>Type</p></td>
<td>
<input type="radio" name="user_type" value= "normal user" /> Normal user
<input type="radio" name="user_type" value= "musician" /> Musician
</td>
</tr>
<tr>
<td><p>Gender</p></td>
<td>
<input type="radio" name="user_gender" value="female" />Female
<input type="radio" name="user_gender" value="male" /> Male </td>
</tr>
<tr>
<td><p>
<input type="submit" name="Submit" id="Submit" value="Submit">
<br />
</p></td>
</tr>
</table>
<input type="hidden" name="ref" value="" />
</form>
and the form code:
<?php
$username = htmlspecialchars($_POST['user_name']);
if (preg_match("/\s/",$username))
{
die("do not use spaces, tabs or newlines in your username");
}
$email = htmlspecialchars($_POST['user_email']);
if (preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/",$email))
{
die("Invalid E-mail address");
}
$Password = htmlspecialchars($_POST['user_password']);
if (preg_match("/\s/",$Password))
{
die("do not use spaces, tabs or newlines in your password");
}
?>
<html>
<body>
Your name is: <?php echo $username; ?><br />
Your password is: <?php echo $Password; ?><br />
Your e-mail: <?php echo $email; ?><br />
<?php echo "Please remember your details for future registration"; ?><br />
<br />
</body>
</html>
<?php
function check_input($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
die($problem);
}
return $data;
}
function show_error($anyError)
{
?>
<html>
<body>
<b>Please correct the following errors:</b><br />
<?php echo $myError; ?>
</body>
</html>
<?php
exit();
}
?>
<?php
$connect = mysql_connect("localhost", "fuser", "projectpass") or die ("connection could not be established.");
mysql_select_db("users");
$insert = "INSERT INTO user(user_name, user_password, user_email, user_type, user_gender)" .
"VALUES ('$username', '$Password', '$email', '$type', '$gender')";
$results = mysql_query($insert) or die (mysql_error());
if(!$results) {
echo "The following SQL failed <hr>$insert";
}
?>
I just thought it would be necessary to add the code to show that I've made changes to it.
here's the screen:
well, nothing I ever do seems to work properly, as it seems that bad luck follows me around whatever I do.
what happens now is that my upload code doesn't seem to work properly. It refuses to identify the files I've uploaded, and even if it does, it doesn't save it.
there are two upload codes here, one is for music and another one is for images.
[upload.php]
ini_set( 'upload_max_filesize', '100M' );
if ( !isset($_FILES['data']['name']) || $_FILES['data']['name'] == '' ) {
die('No input file specified. Please go back and select a file to upload.');
} // End check for file being set
$filetype = 'audio/mpeg';
$upload_path = '/music/';
# Check to see if the filetype is correct
if ($_FILES['data']['type'] != $filetype) {
die('Sorry, your file was not of the ' . $filetype . ' mimetype (yours was ' . $_FILES['data']['type'] . ').');
} // End filetype check
# If file has gotten this far, it is successful
$copy_to = $_SERVER['DOCUMENT_ROOT'] . $upload_path . $_FILES['data']['name'];
# Upload the file
$upload = move_uploaded_file($_FILES['data']['tmp_name'], $copy_to);
# Check to see if upload was successful
if (!$upload) {
die('Sorry, your file could not be uploaded.');
}
echo 'Your file contents are below: <hr>' . file_get_contents($copy_to);
?>```
error:
Warning: move_uploaded_file(G:/xampplite/htdocs/music/1_matabuta.mp3) [function.move-uploaded-file]: failed to open stream: No such file or directory in G:\xampplite\htdocs\mplayer\upload.php on line 20
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'G:\xampplite\tmp\php27.tmp' to 'G:/xampplite/htdocs/music/1_matabuta.mp3' in G:\xampplite\htdocs\mplayer\upload.php on line 20
Sorry, your file could not be uploaded.
[uploadimages.php]
```markup
<?php
ini_set( 'upload_max_filesize', '100M' );
if ( !isset($_FILES['data']['name']) || $_FILES['data']['name'] == '' ) {
die('No input file specified. Please go back and select a file to upload.');
} // End check for file being set
$filetype = array('image/jpg', 'image/jpeg', 'image/bmp', 'image/gif');
$upload_path = '/images/';
# Check to see if the filetype is correct
if ($_FILES['data']['type'] != $filetype) {
die('Sorry, your file was not of the ' . $filetype . ' mimetype (yours was ' . $_FILES['data']['type'] . ').');
} // End filetype check
# If file has gotten this far, it is successful
$copy_to = $_SERVER['DOCUMENT_ROOT'] . $upload_path . $_FILES['data']['name'];
# Upload the file
$upload = move_uploaded_file($_FILES['data']['tmp_name'], $copy_to);
# Check to see if upload was successful
if (!$upload) {
die('Sorry, your file could not be uploaded.');
}
echo 'Your file contents are below: <hr>' . file_get_contents($copy_to);
?>
the error:
Sorry, your file was not of the Array mimetype (yours was image/jpeg).
Sorry, your file was not of the Array mimetype (yours was image/gif).
I should note that this error occurs at both wamp (my laptop) and xampp (my pendrive), except that upload.php also refuses to recognize my filetype whatsoever.
well. now I can make a page where I can edit the information for the users logged into the site. but I have several problems:
a) whenever I try to change any data, be it username, password, or even type of user, it always shows this error:
Duplicate entry '4' for key 'PRIMARY' (the entry number is the user id number)
the code:
user_update.php
if(!isset($_SESSION)){
session_start();}
if(!include('conn.php')){
require('conn.php');}
if(isset($_POST['UserID'])) $UserID = $_POST['UserID'];
if(isset($_POST['Username'])) $Username = $_POST['Username'];
if(isset($_POST['Password'])) $Password = $_POST['Password'];
if(isset($_POST['Group'])) $Group = $_POST['Group'];
$Query = mysql_query("UPDATE user SET `user_name`='$Username',`user_password`='$Password', `user_type`=$Group, user_id=$UserID") or die(mysql_error());
$_SESSION['Err']="User Updated Successfully";
header("Location: control_panel.php?pid=2&uid=$UserID");
?>
<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>User Update</title>
</head>
<body>
</body>
</html>
user_edit.php
if(isset($_GET['uid']))
{
$uid = $_GET['uid'];
$Query = $_GET['uid'];
$Query = mysql_query("SELECT * FROM user WHERE user_id=$uid") or die(mysql_error());
$Result = mysql_fetch_assoc($Query)or die(mysql_error());
} elseif (isset($_GET['uid'])=='' && (!isset($_GET['uid']))){
die();
}
?>
<link href="css.css" rel="stylesheet" type="text/css">
<form action="user_update.php" method="post" id="frmuserpage">
<?php
if(mysql_num_rows($Query)>0)
{
echo mysql_num_rows($Query);
?>
<table width="500" border="1" cellpadding="2" cellspacing="0" bordercolor="#FFFFFF" bgcolor="#CCCCCC">
<tr>
<td>Username</td>
<td>Password</td>
<td>Group</td>
</tr>
<tr>
<td><label>
<input name="Username" type="text" class="textbox" id="user_name" value="<?php echo $Result['user_name'];?>">
</label></td>
<td><label>
<input name="Password" type="text" class="textbox" id="user_password" value="<?php echo $Result['user_password']?>">
</label></td>
<td><label>
<select name="Group" class="textbox" id="user_type">
<option value="1" <?php if($Result['user_type']==1) echo "selected";?>>user</option>
<option value="2" <?php if($Result['user_type']==2) echo "selected";?>>musician</option>
<option value="3" <?php if($Result['user_type']==3) echo "selected";?>>admin</option>
</select>
</label></td>
</tr>
<tr>
<td><input name="UserID" type="hidden" id="user_id" value="<?php echo $Result['user_id'];?>"></td>
<td> </td>
<td> </td>
<td><label>
<input name="Submit" type="submit" class="btn" value="Update" />
</label></td>
</tr>
</table>
<?php
}
else
{
?>
<table width="500" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center">Sorry, No User Found </td>
</tr>
</table>
<?php
}
?>
</form>```
another problem is that everytime a user is logged in, regardless of his usertype, he can simply change the information of the users shown in the control panel, and obviously I want it to be only accessible to the admins of the site.
And I'm not sure if the user profile page is actually working.
```markup<?php
session_start();
$userna=$_SESSION['username'];
$auser=$_SESSION['admin'];
if($nuser){
$userfinal=$nuser;
}elseif($auser){
$userfinal=$auser;
}
if(isset($userfinal)){
$username = $_GET['username'];
$user = mysql_query("SELECT * FROM user WHERE username = '$username'");
$user=mysql_fetch_assoc($user);
if($user['level'] > 1){
die("You cant view an Admins profile!");
}
echo "<h1>User Info</h1>";
echo "<b>Username:".$user['username']."<br>";
echo "<br>";
echo '<form name="backlistfrm" method="post" action="members.php">';
echo '<input type="submit" value="Back to The List">';
echo '</form>';
echo "<br>";
} else {
echo "You are not logged in. Please log in to continue";
}
?>```
edit: nvm, fixed.
well, sorry for necroing, but it seems that I have bumped into another problem as always.
well, first of all it seems that the code for listing users on my site (basically like the "Members Online" section of this site)
well, here's the code for members.php
session_start();
require 'conn.php';
$normuser=$_SESSION['user'];
$musicuser=$_SESSION['musician'];
$adminuser=$_SESSION['admin'];
if($normuser){
$userfinal=$nuser;
}
elseif($musicuser){
$userfinal=$musicuser;
}
elseif($adminuser){
$userfinal=$adminuser;
}
if(isset($userfinal)){
$Members = mysql_query("SELECT user_name FROM user WHERE level ='1' ORDER BY user_name DESC") or die(mysql_error());
$numRowsMembers = mysql_num_rows($Members);
?>
<table border="0">
<?php
for($count = 1; $count <= $numRowsMembers; $count++)
{
$name = mysql_fetch_array($Members);
?>
<tr>
<?php
echo '<td><a href="member_profile.php?username=' . $name['user'] . '">' . $name['user'] . '</a></td>';
?>
</tr>
<?php
}
?>
</table>```
error:
Parse error: parse error in C:\wamp\www\mplayer\members.php on line 40
and I'm also stuck at the profile page:
```markup<?php
session_start();
require 'database.php';
if($nuser){
$userfinal=$nuser;
}elseif($auser){
$userfinal=$auser;
}
if(isset($userfinal)){
$username = $_GET['user_name'];
$user = mysql_query("SELECT * FROM user WHERE user_name = '$username'");
$user=mysql_fetch_assoc($user);
if($user['level'] > 1){
die("You cant view an Admins profile!");
}
echo "<h1>User Info</h1>";
echo "<b>Username:".$user['username']."<br>";
echo "<br>";
echo '<form name="backlistfrm" method="post" action="members.php">';
echo '<input type="submit" value="Back to The List">';
echo '</form>';
echo "<br>";
?>
the error: Parse error: parse error in C:\wamp\www\mplayer\member_profile.php on line 32
and a funny thing with my upload code for both mp3 and images: it keeps on opening it as if it's a textfile, so after I upload it it looks like some weird gibberish about the file I uploaded.
upload.php
ini_set( 'upload_max_filesize', '100M' );
if ( !isset($_FILES['data']['name']) || $_FILES['data']['name'] == '' ) {
die('No input file specified. Please go back and select a file to upload.');
} // End check for file being set
$filetype = 'audio/mpeg';
$upload_path = '/mplayer/music';
# Check to see if the filetype is correct
if ($_FILES['data']['type'] != $filetype) {
die('Sorry, your file was not of the ' . $filetype . ' mimetype (yours was ' . $_FILES['data']['type'] . ').');
} // End filetype check
# If file has gotten this far, it is successful
$copy_to = $_SERVER['DOCUMENT_ROOT'] . $upload_path . $_FILES['data']['name'];
# Upload the file
$upload = move_uploaded_file($_FILES['data']['tmp_name'], $copy_to);
# Check to see if upload was successful
if (!$upload) {
die('Sorry, your file could not be uploaded.');
}
echo 'Your file contents are below: <hr>' . file_get_contents($copy_to);
?>```
here's an example of the result:
[](http://img59.imageshack.us/i/uploadj.jpg/)
I'm gonna give you a big tip atleast i think it is :) most of the times am using it myself
For example this pseudo
username = some kind of data getting a username
working with the username here
will generate an error but you've got no idea where it's going wrong then just echo the variable so you can check if it's filled :)
fuser wrote: and a funny thing with my upload code for both mp3 and images: it keeps on opening it as if it's a textfile, so after I upload it it looks like some weird gibberish about the file I uploaded.
upload.php
ini_set( 'upload_max_filesize', '100M' );
if ( !isset($_FILES['data']['name']) || $_FILES['data']['name'] == '' ) {
die('No input file specified. Please go back and select a file to upload.');
} // End check for file being set
$filetype = 'audio/mpeg';
$upload_path = '/mplayer/music';
# Check to see if the filetype is correct
if ($_FILES['data']['type'] != $filetype) {
die('Sorry, your file was not of the ' . $filetype . ' mimetype (yours was ' . $_FILES['data']['type'] . ').');
} // End filetype check
# If file has gotten this far, it is successful
$copy_to = $_SERVER['DOCUMENT_ROOT'] . $upload_path . $_FILES['data']['name'];
# Upload the file
$upload = move_uploaded_file($_FILES['data']['tmp_name'], $copy_to);
# Check to see if upload was successful
if (!$upload) {
die('Sorry, your file could not be uploaded.');
}
echo 'Your file contents are below: <hr>' . file_get_contents($copy_to);
?>```
here's an example of the result:
[](http://img59.imageshack.us/i/uploadj.jpg/)
file_get_contents() literally opens the file like notepad does; so echo'ing out the contents is just gonna give you the same results as opening up a jpg or mp3 in notepad.
well, I've found a script from http://www.jp77.org/dl.php?filename=LSv2.0.4d.zip which seems to help me with my user settings (namely, defining the usertypes, etc), but as usual I always run into problems.
edit: turns out all I had to do was to run it in wamp instead of xampp. however, after registration it sends a confirmation e-mail to which I have to check in order to proceed with registration. The issue here is that the server I have is on my own computer, and my project forbids me from renting out a server or even setting it up online for the time being. And also the fact that I usually type in fake e-mail addresses also doesn't help, I guess.
So, I think the best way to do it is that after a user is registered, the user can immediately log on without having to check for a confirmation e-mail.
these are the code which I think are related to the registration process:
/**
* Register.php
*
* Displays the registration form if the user needs to sign-up,
* or lets the user know, if he's already logged in, that he
* can't register another name.
*
* Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
* Last Updated: August 2, 2009 by Ivan Novak
*/
include("include/session.php");
?>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Jpmaster77's Login Script</title>
<link rel="stylesheet" href="-css/960/reset.css" type="text/css" />
<link rel="stylesheet" href="-css/960/960.css" type="text/css" />
<link rel="stylesheet" href="-css/960/text.css" type="text/css" />
<link rel="stylesheet" href="-css/style.css" type="text/css" />
</head>
<body>
<div id="main" class="container_12">
<?php
/**
* The user is already logged in, not allowed to register.
*/
if($session->logged_in){
echo "<h1>Registered</h1>";
echo "<p>We're sorry <b>$session->username</b>, but you've already registered. "
."<a href=\"main.php\">Main</a>.</p>";
}
/**
* The user has submitted the registration form and the
* results have been processed.
*/
else if(isset($_SESSION['regsuccess'])){
/* Registration was successful */
if($_SESSION['regsuccess']){
echo "<h1>Registered!</h1>";
if(EMAIL_WELCOME){
echo "<p>Thankyou <b>".$_SESSION['reguname']."</b>, you have been sent a confirmation email which should be arriving shortly. Please confirm your registration before you continue.<br />Back to <a href='main.php'>Main</a></p>";
}else{
echo "<p>Thank you <b>".$_SESSION['reguname']."</b>, your information has been added to the database, "
."you may now <a href=\"main.php\">log in</a>.</p>";
}
}
/* Registration failed */
else{
echo "<h1>Registration Failed</h1>";
echo "<p>We're sorry, but an error has occurred and your registration for the username <b>".$_SESSION['reguname']."</b>, "
."could not be completed.<br>Please try again at a later time.</p>";
}
unset($_SESSION['regsuccess']);
unset($_SESSION['reguname']);
}
/**
* The user has not filled out the registration form yet.
* Below is the page with the sign-up form, the names
* of the input fields are important and should not
* be changed.
*/
else{
?>
<h1>Register</h1>
<?php
if($form->num_errors > 0){
echo "<td><font size=\"2\" color=\"#ff0000\">".$form->num_errors." error(s) found</font></td>";
}
?>
<div id="register">
<form action="process.php" method="POST">
<p class="textinput">Name: </p><p><input type="text" name="name" maxlength="30" value="<?php echo $form->value("name"); ?>"><?php echo $form->error("name"); ?></p>
<p class="textinput">Username: </p><p><input type="text" name="user" maxlength="30" value="<?php echo $form->value("user"); ?>"><?php echo $form->error("user"); ?></p>
<p class="textinput">Password: </p><p><input type="password" name="pass" maxlength="30" value="<?php echo $form->value("pass"); ?>"><?php echo $form->error("pass"); ?></p>
<p class="textinput">Email: </p><p><input type="text" name="email" maxlength="50" value="<?php echo $form->value("email"); ?>"><?php echo $form->error("email"); ?></p>
<p class="textinput"><input type="hidden" name="subjoin" value="1"><input type="submit" value="Join!"></p>
<p><a href="main.php">[Back to Main]</a></p>
</form>
</div>
<?php
}
?>
</div>
</body>
</html>
/**
* Session.php
*
* The Session class is meant to simplify the task of keeping
* track of logged in users and also guests.
*
* Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
* Last Updated: August 2, 2009 by Ivan Novak
*/
include("database.php");
include("mailer.php");
include("form.php");
class Session
{
var $username; //Username given on sign-up
var $userid; //Random value generated on current login
var $userlevel; //The level to which the user pertains
var $time; //Time user was last active (page loaded)
var $logged_in; //True if user is logged in, false otherwise
var $userinfo = array(); //The array holding all user info
var $url; //The page url current being viewed
var $referrer; //Last recorded site page viewed
/**
* Note: referrer should really only be considered the actual
* page referrer in process.php, any other time it may be
* inaccurate.
*/
/* Class constructor */
function Session(){
$this->time = time();
$this->startSession();
}
/**
* startSession - Performs all the actions necessary to
* initialize this session object. Tries to determine if the
* the user has logged in already, and sets the variables
* accordingly. Also takes advantage of this page load to
* update the active visitors tables.
*/
function startSession(){
global $database; //The database connection
session_start(); //Tell PHP to start the session
/* Determine if user is logged in */
$this->logged_in = $this->checkLogin();
/**
* Set guest value to users not logged in, and update
* active guests table accordingly.
*/
if(!$this->logged_in){
$this->username = $_SESSION['username'] = GUEST_NAME;
$this->userlevel = GUEST_LEVEL;
$database->addActiveGuest($_SERVER['REMOTE_ADDR'], $this->time);
}
/* Update users last active timestamp */
else{
$database->addActiveUser($this->username, $this->time);
}
/* Remove inactive visitors from database */
$database->removeInactiveUsers();
$database->removeInactiveGuests();
/* Set referrer page */
if(isset($_SESSION['url'])){
$this->referrer = $_SESSION['url'];
}else{
$this->referrer = "/";
}
/* Set current url */
$this->url = $_SESSION['url'] = $_SERVER['PHP_SELF'];
}
/**
* checkLogin - Checks if the user has already previously
* logged in, and a session with the user has already been
* established. Also checks to see if user has been remembered.
* If so, the database is queried to make sure of the user's
* authenticity. Returns true if the user has logged in.
*/
function checkLogin(){
global $database; //The database connection
/* Check if user has been remembered */
if(isset($_COOKIE['cookname']) && isset($_COOKIE['cookid'])){
$this->username = $_SESSION['username'] = $_COOKIE['cookname'];
$this->userid = $_SESSION['userid'] = $_COOKIE['cookid'];
}
/* Username and userid have been set and not guest */
if(isset($_SESSION['username']) && isset($_SESSION['userid']) &&
$_SESSION['username'] != GUEST_NAME){
/* Confirm that username and userid are valid */
if($database->confirmUserID($_SESSION['username'], $_SESSION['userid']) != 0){
/* Variables are incorrect, user not logged in */
unset($_SESSION['username']);
unset($_SESSION['userid']);
return false;
}
/* User is logged in, set class variables */
$this->userinfo = $database->getUserInfo($_SESSION['username']);
$this->username = $this->userinfo['username'];
$this->userid = $this->userinfo['userid'];
$this->userlevel = $this->userinfo['userlevel'];
return true;
}
/* User not logged in */
else{
return false;
}
}
/**
* login - The user has submitted his username and password
* through the login form, this function checks the authenticity
* of that information in the database and creates the session.
* Effectively logging in the user if all goes well.
*/
function login($subuser, $subpass, $subremember){
global $database, $form; //The database and form object
/* Username error checking */
$field = "user"; //Use field name for username
$q = "SELECT valid FROM ".TBL_USERS." WHERE username='$subuser'";
$valid = $database->query($q);
$valid = mysql_fetch_array($valid);
if(!$subuser || strlen($subuser = trim($subuser)) == 0){
$form->setError($field, "* Username not entered");
}
else{
/* Check if username is not alphanumeric */
if(!eregi("^([0-9a-z])*$", $subuser)){
$form->setError($field, "* Username not alphanumeric");
}
}
/* Password error checking */
$field = "pass"; //Use field name for password
if(!$subpass){
$form->setError($field, "* Password not entered");
}
/* Return if form errors exist */
if($form->num_errors > 0){
return false;
}
/* Checks that username is in database and password is correct */
$subuser = stripslashes($subuser);
$result = $database->confirmUserPass($subuser, md5($subpass));
/* Check error codes */
if($result == 1){
$field = "user";
$form->setError($field, "* Username not found");
}
else if($result == 2){
$field = "pass";
$form->setError($field, "* Invalid password");
}
/* Return if form errors exist */
if($form->num_errors > 0){
return false;
}
if(EMAIL_WELCOME){
if($valid['valid'] == 0){
$form->setError($field, "* User's account has not yet been confirmed.");
}
}
/* Return if form errors exist */
if($form->num_errors > 0){
return false;
}
/* Username and password correct, register session variables */
$this->userinfo = $database->getUserInfo($subuser);
$this->username = $_SESSION['username'] = $this->userinfo['username'];
$this->userid = $_SESSION['userid'] = $this->generateRandID();
$this->userlevel = $this->userinfo['userlevel'];
/* Insert userid into database and update active users table */
$database->updateUserField($this->username, "userid", $this->userid);
$database->addActiveUser($this->username, $this->time);
$database->removeActiveGuest($_SERVER['REMOTE_ADDR']);
/**
* This is the cool part: the user has requested that we remember that
* he's logged in, so we set two cookies. One to hold his username,
* and one to hold his random value userid. It expires by the time
* specified in constants.php. Now, next time he comes to our site, we will
* log him in automatically, but only if he didn't log out before he left.
*/
if($subremember){
setcookie("cookname", $this->username, time()+COOKIE_EXPIRE, COOKIE_PATH);
setcookie("cookid", $this->userid, time()+COOKIE_EXPIRE, COOKIE_PATH);
}
/* Login completed successfully */
return true;
}
/**
* logout - Gets called when the user wants to be logged out of the
* website. It deletes any cookies that were stored on the users
* computer as a result of him wanting to be remembered, and also
* unsets session variables and demotes his user level to guest.
*/
function logout(){
global $database; //The database connection
/**
* Delete cookies - the time must be in the past,
* so just negate what you added when creating the
* cookie.
*/
if(isset($_COOKIE['cookname']) && isset($_COOKIE['cookid'])){
setcookie("cookname", "", time()-COOKIE_EXPIRE, COOKIE_PATH);
setcookie("cookid", "", time()-COOKIE_EXPIRE, COOKIE_PATH);
}
/* Unset PHP session variables */
unset($_SESSION['username']);
unset($_SESSION['userid']);
/* Reflect fact that user has logged out */
$this->logged_in = false;
/**
* Remove from active users table and add to
* active guests tables.
*/
$database->removeActiveUser($this->username);
$database->addActiveGuest($_SERVER['REMOTE_ADDR'], $this->time);
/* Set user level to guest */
$this->username = GUEST_NAME;
$this->userlevel = GUEST_LEVEL;
}
/**
* register - Gets called when the user has just submitted the
* registration form. Determines if there were any errors with
* the entry fields, if so, it records the errors and returns
* 1. If no errors were found, it registers the new user and
* returns 0. Returns 2 if registration failed.
*/
function register($subuser, $subpass, $subemail, $subname){
global $database, $form, $mailer; //The database, form and mailer object
/* Username error checking */
$field = "user"; //Use field name for username
if(!$subuser || strlen($subuser = trim($subuser)) == 0){
$form->setError($field, "* Username not entered");
}
else{
/* Spruce up username, check length */
$subuser = stripslashes($subuser);
if(strlen($subuser) < 5){
$form->setError($field, "* Username below 5 characters");
}
else if(strlen($subuser) > 30){
$form->setError($field, "* Username above 30 characters");
}
/* Check if username is not alphanumeric */
else if(!eregi("^([0-9a-z])+$", $subuser)){
$form->setError($field, "* Username not alphanumeric");
}
/* Check if username is reserved */
else if(strcasecmp($subuser, GUEST_NAME) == 0){
$form->setError($field, "* Username reserved word");
}
/* Check if username is already in use */
else if($database->usernameTaken($subuser)){
$form->setError($field, "* Username already in use");
}
/* Check if username is banned */
else if($database->usernameBanned($subuser)){
$form->setError($field, "* Username banned");
}
}
/* Password error checking */
$field = "pass"; //Use field name for password
if(!$subpass){
$form->setError($field, "* Password not entered");
}
else{
/* Spruce up password and check length*/
$subpass = stripslashes($subpass);
if(strlen($subpass) < 4){
$form->setError($field, "* Password too short");
}
/* Check if password is not alphanumeric */
else if(!eregi("^([0-9a-z])+$", ($subpass = trim($subpass)))){
$form->setError($field, "* Password not alphanumeric");
}
/**
* Note: I trimmed the password only after I checked the length
* because if you fill the password field up with spaces
* it looks like a lot more characters than 4, so it looks
* kind of stupid to report "password too short".
*/
}
/* Email error checking */
$field = "email"; //Use field name for email
if(!$subemail || strlen($subemail = trim($subemail)) == 0){
$form->setError($field, "* Email not entered");
}
else{
/* Check if valid email address */
$regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*"
."@[a-z0-9-]+(\.[a-z0-9-]{1,})*"
."\.([a-z]{2,}){1}$";
if(!eregi($regex,$subemail)){
$form->setError($field, "* Email invalid");
}
/* Check if email is already in use */
if($database->emailTaken($subemail)){
$form->setError($field, "* Email already in use");
}
$subemail = stripslashes($subemail);
}
/* Name error checking */
$field = "name";
if(!$subname || strlen($subname = trim($subname)) == 0){
$form->setError($field, "* Name not entered");
} else {
$subname = stripslashes($subname);
}
$randid = $this->generateRandID();
/* Errors exist, have user correct them */
if($form->num_errors > 0){
return 1; //Errors with form
}
/* No errors, add the new account to the */
else{
if($database->addNewUser($subuser, md5($subpass), $subemail, $randid, $subname)){
if(EMAIL_WELCOME){
$mailer->sendWelcome($subuser,$subemail,$subpass,$randid);
}
return 0; //New user added succesfully
}else{
return 2; //Registration attempt failed
}
}
}
/**
* editAccount - Attempts to edit the user's account information
* including the password, which it first makes sure is correct
* if entered, if so and the new password is in the right
* format, the change is made. All other fields are changed
* automatically.
*/
function editAccount($subcurpass, $subnewpass, $subemail, $subname){
global $database, $form; //The database and form object
/* New password entered */
if($subnewpass){
/* Current Password error checking */
$field = "curpass"; //Use field name for current password
if(!$subcurpass){
$form->setError($field, "* Current Password not entered");
}
else{
/* Check if password too short or is not alphanumeric */
$subcurpass = stripslashes($subcurpass);
if(strlen($subcurpass) < 4 ||
!eregi("^([0-9a-z])+$", ($subcurpass = trim($subcurpass)))){
$form->setError($field, "* Current Password incorrect");
}
/* Password entered is incorrect */
if($database->confirmUserPass($this->username,md5($subcurpass)) != 0){
$form->setError($field, "* Current Password incorrect");
}
}
/* New Password error checking */
$field = "newpass"; //Use field name for new password
/* Spruce up password and check length*/
$subpass = stripslashes($subnewpass);
if(strlen($subnewpass) < 4){
$form->setError($field, "* New Password too short");
}
/* Check if password is not alphanumeric */
else if(!eregi("^([0-9a-z])+$", ($subnewpass = trim($subnewpass)))){
$form->setError($field, "* New Password not alphanumeric");
}
}
/* Change password attempted */
else if($subcurpass){
/* New Password error reporting */
$field = "newpass"; //Use field name for new password
$form->setError($field, "* New Password not entered");
}
/* Email error checking */
$field = "email"; //Use field name for email
if($subemail && strlen($subemail = trim($subemail)) > 0){
/* Check if valid email address */
$regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*"
."@[a-z0-9-]+(\.[a-z0-9-]{1,})*"
."\.([a-z]{2,}){1}$";
if(!eregi($regex,$subemail)){
$form->setError($field, "* Email invalid");
}
$subemail = stripslashes($subemail);
}
/* Name error checking */
$field = "name";
if(!$subname || strlen($subname = trim($subname)) == 0){
$form->setError($field, "* Name not entered");
} else {
$subname = stripslashes($subname);
}
/* Errors exist, have user correct them */
if($form->num_errors > 0){
return false; //Errors with form
}
/* Update password since there were no errors */
if($subcurpass && $subnewpass){
$database->updateUserField($this->username,"password",md5($subnewpass));
}
/* Change Email */
if($subemail){
$database->updateUserField($this->username,"email",$subemail);
}
/* Change Name */
if($subname){
$database->updateUserField($this->username,"name",$subname);
}
/* Success! */
return true;
}
/**
* isAdmin - Returns true if currently logged in user is
* an administrator, false otherwise.
*/
function isAdmin(){
return ($this->userlevel == ADMIN_LEVEL ||
$this->username == ADMIN_NAME);
}
/**
* isAuthor - Returns true if currently logged in user is
* an author or an administrator, false otherwise.
*/
function isAuthor(){
return ($this->userlevel == AUTHOR_LEVEL ||
$this->userlevel == ADMIN_LEVEL);
}
/**
* generateRandID - Generates a string made up of randomized
* letters (lower and upper case) and digits and returns
* the md5 hash of it to be used as a userid.
*/
function generateRandID(){
return md5($this->generateRandStr(16));
}
/**
* generateRandStr - Generates a string made up of randomized
* letters (lower and upper case) and digits, the length
* is a specified parameter.
*/
function generateRandStr($length){
$randstr = "";
for($i=0; $i<$length; $i++){
$randnum = mt_rand(0,61);
if($randnum < 10){
$randstr .= chr($randnum+48);
}else if($randnum < 36){
$randstr .= chr($randnum+55);
}else{
$randstr .= chr($randnum+61);
}
}
return $randstr;
}
};
/**
* Initialize session object - This must be initialized before
* the form object because the form uses session variables,
* which cannot be accessed unless the session has started.
*/
$session = new Session;
/* Initialize form object */
$form = new Form;
?>```
```markup<?php
/**
* Mailer.php
*
* The Mailer class is meant to simplify the task of sending
* emails to users. Note: this email system will not work
* if your server is not setup to send mail.
*
* If you are running Windows and want a mail server, check
* out this website to see a list of freeware programs:
* <http://www.snapfiles.com/freeware/server/fwmailserver.html>
*
* Written by: Jpmaster77 a.k.a. The Grandmaster of C++ (GMC)
* Last Updated: August 2, 2009 by Ivan Novak
*/
class Mailer
{
/**
* sendWelcome - Sends a welcome message to the newly
* registered user, also supplying the username and
* password.
*/
function sendWelcome($user, $email, $pass, $userid){
$from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">";
$subject = "Jpmaster77's Site - Welcome!";
$body = $user.",\n\n"
."Welcome! You've just registered at Jpmaster77's Site "
."with the following information:\n\n"
."Username: ".$user."\n"
."Password: ".$pass."\n\n"
."Before you can login you need to activate your\n"
."account by clicking on this link:\n\n"
."http://localhost:8888/jpsystem/LS2dev/valid.php?qs1=".$user."&qs2=".$userid."\n\n"
."If you ever lose or forget your password, a new "
."password will be generated for you and sent to this "
."email address, if you would like to change your "
."email address you can do so by going to the "
."My Account page after signing in.\n\n"
."- Jpmaster77's Site";
return mail($email,$subject,$body,$from);
}
/**
* sendConfirmation - Sends a confirmation to users
* who click a "Send confirmation" button. This
* only needs to be used if the EMAIL_WELCOME constant
* is changed to true and the user's 'valid' field is 0
*/
function sendConfirmation($user, $userid, $email){
$from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">";
$subject = "jpmaster77's Site - Welcome!";
$body = $user.",\n\n"
."We're sorry for the inconvenience. We are making\n"
."our website more secure for both your and our \n"
."benefit.\n\n"
."To activate your account you can either click on the\n"
."following link or copy the link and paste it into your\n"
."address bar.\n\n"
."http://localhost:8888/jpsystem/LS2dev/valid.php?qs1=".$user."&qs2=".$userid."\n\n"
."We here at Jpmaster77's Site hope you continue to\n"
."enjoy our wonderful service.\n\n"
."Sincerely,\n\n"
."- Jpmaster77's Site";
return mail($email,$subject,$body,$from);
}
/**
* sendNewPass - Sends the newly generated password
* to the user's email address that was specified at
* sign-up.
*/
function sendNewPass($user, $email, $pass){
$from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">";
$subject = "Jpmaster77's Site - Your new password";
$body = $user.",\n\n"
."We've generated a new password for you at your "
."request, you can use this new password with your "
."username to log in to Jpmaster77's Site.\n\n"
."Username: ".$user."\n"
."New Password: ".$pass."\n\n"
."It is recommended that you change your password "
."to something that is easier to remember, which "
."can be done by going to the My Account page "
."after signing in.\n\n"
."- Jpmaster77's Site";
return mail($email,$subject,$body,$from);
}
};
/* Initialize mailer object */
$mailer = new Mailer;
?>
Alright, this whole thread has gotten really silly. You literally post large reams of code with a simple error like "parse error" or "error in sql syntax" or things that aren't even an error (type "Array", file_get_contents, etc.).
You get parse errors when you write invalid code. In the first parse error, you nested <?php tags inside of each other. In the second, you didn't close an if conditional. You could have found both had you actually tried.
Throw out the script you downloaded and are trying to modify, and just start from scratch. It's okay to learn from other people's code, but you'll never learn unless you write your own.
When you get an error like "parse error" or "unexpected T_STRING" or unexpected "T_ELSE" or whatever other error, try to understand the error. Don't just run to the forum with 4 pages of code and a wish.
- Read the error a few times over if you don't get what it's saying.
- Look at line numbers an error references, if any.
- Output variables that don't seem to be what you expect them to be.
- For arrays, use var_dump() to output them.
- Try everything else you can think of.
- When all else fails, Google the error text. Seriously, thousands of people have had your same error before… doesn't matter what it is.
Then, if you're still stuck or don't understand after having read through other forum threads of people getting helped with these small errors… Post here. We don't mind helping, but you're not TRYING. At all.
define wrote: Alright, this whole thread has gotten really silly. You literally post large reams of code with a simple error like "parse error" or "error in sql syntax" or things that aren't even an error (type "Array", file_get_contents, etc.).
You get parse errors when you write invalid code. In the first parse error, you nested <?php tags inside of each other. In the second, you didn't close an if conditional. You could have found both had you actually tried.
Throw out the script you downloaded and are trying to modify, and just start from scratch. It's okay to learn from other people's code, but you'll never learn unless you write your own.
When you get an error like "parse error" or "unexpected T_STRING" or unexpected "T_ELSE" or whatever other error, try to understand the error. Don't just run to the forum with 4 pages of code and a wish.
- Read the error a few times over if you don't get what it's saying.
- Look at line numbers an error references, if any.
- Output variables that don't seem to be what you expect them to be.
- For arrays, use var_dump() to output them.
- Try everything else you can think of.
- When all else fails, Google the error text. Seriously, thousands of people have had your same error before… doesn't matter what it is.
Then, if you're still stuck or don't understand after having read through other forum threads of people getting helped with these small errors… Post here. We don't mind helping, but you're not TRYING. At all.
well, I guess I'm not really used to PHP, and I usually panic easily when something happens, and I usually read the error text over and over again, but most of the time I'm unable to figure the answer out. Thanks for the advice.
fuser wrote: well, I guess I'm not really used to PHP, and I usually panic easily when something happens, and I usually read the error text over and over again, but most of the time I'm unable to figure the answer out. I know… and I am genuinely giving advice. Until you stop panicking, you'll continue to be unable to figure the answer out and will, ultimately, never get used to PHP.
There's nothing wrong with asking for help; there's something to be said for learning how to fix the problem when it's a problem that you can fix, though. Otherwise, you're going to continue to encounter the same basic issues that you have been encountering, and you'll continue to get stuck instead of knowing how to solve them for the next time they occur (because they will occur again and again as you progress).
So, in case you have, don't take offense to what I'm saying. Everything I'm saying is with the goal of helping you improve as a PHP programmer. :)
no, there's no error whatsoever. the issue here is that the code I used sends a confirmation e-mail which the user has to click on before he can log in.
the problem now is that I can't host my project on an online server, so I can't send and receive emails, so I'm locked out of my own site, so I think the best way to do this is to allow the user to log into the site as soon as he has registered to the site without the need of the validation e-mail.
and I'm in a major panic mode now. I have only a week left to present my project, so I'm feeling quite fucked.
/**
- sendConfirmation - Sends a confirmation to users
- who click a "Send confirmation" button. This
- only needs to be used if the EMAIL_WELCOME constant
- is changed to true and the user's 'valid' field is 0 */
put ur user's valid field in db on 1 or put the constant on false and u can login to ur own site again =)
for testing purposes i would say hire a cheap ass server or google for free webservers with smtp
MoshBat wrote: [quote]michelfalke wrote: /**
- sendConfirmation - Sends a confirmation to users
- who click a "Send confirmation" button. This
- only needs to be used if the EMAIL_WELCOME constant
- is changed to true and the user's 'valid' field is 0 */
put ur user's valid field in db on 1 or put the constant on false and u can login to ur own site again =)
for testing purposes i would say hire a cheap ass server or google for free webservers with smtp He can't use a server, other than localhost. And for the love of God, use full words, and people might take what you say seriously, or better yet, read it without thinking you're 11.[/quote]
I don't know what u'r using on localhost but i'm using a database there aswell. And the comment in the script says what to do aswell.
And for testing purposes with the email validation there will come a point which i mentioned. Hire a server or check the internet for a free host.
well, of course I'm using a database as well.
btw, I have an issue, nothing too big but it's annoying nonetheless.
Following the tutorial showed at: http://www.zimmertech.com/tutorials/php/25/comment-form-script-tutorial.php I now have a working comment box, but there are a few problems that still puzzles me. The problem is that, after I implement the shoutbox at any artist's profile page, it will show an error like this:
Notice: Undefined variable: PHP_SELF in C:\wamp\www\mplayer\artists\c14.php on line 79
but after I post a comment, it shows that my comment is accepted, and then it shows this error on the redirect page:
Notice: Undefined index: tuturl in C:\wamp\www\mplayer\artists\submitcomment.php on line 16
Notice: Undefined index: tutid2 in C:\wamp\www\mplayer\artists\submitcomment.php on line 17
Notice: Undefined index: name in C:\wamp\www\mplayer\artists\submitcomment.php on line 18
Notice: Undefined index: url in C:\wamp\www\mplayer\artists\submitcomment.php on line 19
Notice: Undefined index: email in C:\wamp\www\mplayer\artists\submitcomment.php on line 20
Notice: Undefined index: message in C:\wamp\www\mplayer\artists\submitcomment.php on line 21 Submission Successful Your comment has been submitted. You will now be redirected back to the last page you visited. Thanks!
So, I usually have to go a few pages back, and then have re-visit the page I posted a comment earlier to see if it is included (usually it is).
The problem is that even though it works, the error messages still makes me think that I must've done something wrong, although I'm not sure what.
$PHP_SELF only works when you have register_globals on in your php.ini. Since it's a security risk, don't enable it. Just change $PHP_SELF to $_SERVER['PHP_SELF'].
For lines 16-21 of the submit php script, it looks like it's not finding those indexes in the $_POST superglobal. Right above line 16, put this:
var_dump($_POST);
… and post what it comes back with here. It will be at the top of the page.
define wrote: $PHP_SELF only works when you have register_globals on in your php.ini. Since it's a security risk, don't enable it. Just change $PHP_SELF to $_SERVER['PHP_SELF'].
For lines 16-21 of the submit php script, it looks like it's not finding those indexes in the $_POST superglobal. Right above line 16, put this:
var_dump($_POST);
… and post what it comes back with here. It will be at the top of the page.
well, I implemented your suggestions, but what it came out is:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in E:\xampplite\htdocs\mplayer\artists\c14.php on line 71
to be fair, I tried to change $_SERVER['PHP_SELF']. with and without the notation point.
I also have a slight problem that I can't figure out. My site has an upload and download feature, and while the upload feature works, I can't seem to download any files.
results in:
Here's the upload and download code:
<?php
ini_set( 'upload_max_filesize', '100M' );
$uploadDir = 'C:\wamp\www\mplayer\music\music';
$filetype = 'audio/mpeg';
if(isset($_POST['upload']))
{
$fileName = $_FILES['data']['name'];
$tmpName = $_FILES['data']['tmp_name'];
$fileSize = $_FILES['data']['size'];
$fileType = $_FILES['data']['type'];
$filePath = $uploadDir . $fileName;
$result = move_uploaded_file($tmpName, $filePath);
if (!$result) {
echo "Error uploading file";
exit;
}
include 'conn1.php';
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
}
$query = "INSERT INTO upload (name, size, type, path ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$filePath')";
mysql_query($query) or die('Error, query failed : ' . mysql_error());
echo "<br>Files uploaded<br>";
}
?>
(upload)
<?php
$server="localhost";
$database="uploads";
$admin="fuser";
$password="projectpass";
$link=mysql_connect($server,$admin,$password);
mysql_select_db($database,$link);
$query = "SELECT id, name FROM upload";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result) == 0)
{
echo "Database is empty <br>";
}
else
{
while(list($id, $name) = mysql_fetch_array($result))
{
?>
<a href="download.php?id=<?php echo urlencode($id);?>"><?php echo urlencode($name);?></a> <br>
<?php
}
}
mysql_close($link);
?>
<?php
if(isset($_GET['id']))
{
$server="localhost";
$database="uploads";
$admin="fuser";
$password="projectpass";
$link=mysql_connect($server,$admin,$password);
mysql_select_db($database,$link);
$id=$_GET['id'];
$query = "SELECT name, type, size, content " .
"FROM upload WHERE id = '$id'";
$result = mysql_query($query) or die('Error, query failed');
list($name, $type, $size, $content)=mysql_fetch_array($result);
header("Content-length: $size");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$name");
echo $content;
mysql_close($link);
exit;
}
?>
[download]
fuser wrote: well, I implemented your suggestions, but what it came out is:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in E:\xampplite\htdocs\mplayer\artists\c14.php on line 71
to be fair, I tried to change $_SERVER['PHP_SELF']. with and without the notation point.
Unless you removed about 8 lines of code in the process, that error is occurring on a different line. Also, after referencing the comment form link you posted in one of your previous posts, I found that they were doing this:
submitComments("1","$PHP_SELF");
… which is stupid. Quotes are not needed around either of those, and that may be where you're encountering an issue… especially if you did this:
submitComments("1","$_SERVER['PHP_SELF']");
It should be this:
submitComments(1,$_SERVER['PHP_SELF']);
For reference, if you want to have an array value in a string, you'd have to surround it with {}. For example:
$str = "I like to code {$language[0]} on {$day['third']}";
fuser wrote: I also have a slight problem that I can't figure out. My site has an upload and download feature, and while the upload feature works, I can't seem to download any files.
<?php
if(isset($_GET['id']))
{
...
$query = "SELECT name, type, size, content " .
"FROM upload WHERE id = '$id'";
$result = mysql_query($query) or die(**mysql_error()**);
...
}
?>
(download) Start by making the change in bold above; that will give you a more relevant error message. Also, try surrounding the field names in your query with ` characters, since "type" may or may not be a MySQL keyword. Like this:
"SELECT name
, type
, size
, content
FROM upload WHERE id = '$id'"
Also, if your "id" field in the table is not a string, there's no need to put ' around $id in the query.
I implemented the changes you suggested, but I got a few problems I
will show through screenshots:
post comments:
download:
after I try to download any of the files listed, I get this:
If I save the file to disc, it doesn't show the filetype of the file
downloaded.
And if I chose the open file option, it opens a page similar to the
download page, and then I get this:
well, I also managed to fix the problem in the last post, and this is the last request for help, I promise (there's three days left, and everything's done except this one)
I just realised that I had to limit the upload feature of my site, so that only registered users can upload content on my site. The upload and user tables are in the same database, and when using the query
right join upload on users.id
where users.id = upload.id```
it shows the username of the that had uploaded the content. The problem now is that even unregistered users can upload files to this site, so is there any suggestions on restricting this from happening?
fuser wrote: yeah, darksun helped me walkthrough it. thanks for all those that've replied for this thread. And wish me luck, I need it since if I fail, I might have to repeat another semester. Glad you got help. What's darksun up to these days?
… and, no offense, but if any of this was information taught in the current semester, you should consider relearning it, regardless.
nah, the whole web programming class wasn't taught this semester, it was taught way earlier when I started studying in college. There's not much technical classes this semester, mainly business. And if I recall correctly, I got a B for my web programming class.
This is a final year project, basically a project I have to work on so that I can graduate. You know how terrible it can get if I fail it.
if you're gonna scold me for necroing my own thread, go choke on your own vomit and I hope that your family gets eaten.
Well, I basically flunked it. I have to re-do the entire thing from scratch cause they don't like the damned thing. Why do I even bother telling you people?
You're just gonna make fun of me anyway.
fuser wrote: Well, I basically flunked it. I have to re-do the entire thing from scratch cause they don't like the damned thing. Why do I even bother telling you people?
You're just gonna make fun of me anyway.
Your misfortune isn't funny to me, but your attitude about the whole thing is.
From the start of this thread to the last post before the flunk, you spent a month, possibly off and on, mostly posting reams of code (sometimes yours, sometimes not) and asking us to troubleshoot it. In the course of that month, you should have spent…
2-3 weeks: Learning PHP through simple examples online to demonstrate concepts and asking general PHP questions here if needed
1-2 weeks: Doing the project start to finish.
The reason why you failed is because you failed to learn enough to actually do what was needed to pass. So, now you have a chance to do it right this time.
Learn PHP. If you have questions, ask. I always answer PHP-related PMs, and I'm sure others do, too. Also, there are loads of threads on PHP topics in the web whatever category of the forum. There are LOADS of threads at PHPFreaks, also, and there are obviously more users there that are experienced with PHP than there are here.
You can learn… if you choose to.