The below script is causing me some issues all im trying to do is register a user with the database
when it is run the page posts and returns the same HTML form as far as i can tell (well and educated guess really) is that the script runs the 1st set of IF statements (to check for empty fields) as when the form reappears it remains empty. Yet it seems to ignore the second set of IF statements (Connect and Insert data) as the database is not updated and the confirmation or erro messages arent displayed
The connection file mysql_connect.php is located outside of the public_html folder in a folder called private
the file structure is
server
-->public_html
--> web content files
-->private
-->mysql_connect.php
Code: Select all
<?php # Register.php
$page_title = 'Star Racing Registration';
include ('./header.inc');
?>
<BR><BR>
<FONT FACE="Tahoma"><B>
<div id="navcontainer">
<ul id="navlist">
<li>| <A HREF="index.php">Home</a></li> |
<li><A HREF="about.php"> About Us</a></li> |
<li><A HREF="tips.php"> Tips</a></li> |
<li><A HREF="past.php"> Past Results</a></li> |
<li><A HREF="account.php"> My Account</A></li> |
<li><A HREF="faq.php"> FAQ</A></li> |
<li><A HREF="links.php">Links</A></li> |
</ul>
</div>
<?php
if (isset($_POST['submit']))
{ // Handle Form
$message = NULL; //Create Empty message
if (empty($_POST['username']))
{ $un = FALSE;
$message = '<P><FONT COLOR="red">You Need to enter your Username!!</P></FONT>';
}
else {
$un = $_POST['username'];
}
if (empty($_POST['password']))
{ $pw = FALSE;
$message = '<P><FONT COLOR="red">You Need to
enter your Password!!</P></FONT>';
}
else {
if ($_POST['password'] == $_POST['confirmpass'])
{
$pw = $_POST['password'];
}
else {
$pw = FALSE;
$message = '<P><FONT COLOR="red">Your Password did not match!! Please try again</P></FONT>';
}
}
if (empty($_POST['first_name']))
{ $first = FALSE;
$message = '<P><FONT COLOR="red">You Need to
enter your First name!!</P></FONT>';
}
else {
$first = $_POST['first_name'];
}
if (empty($_POST['last_name']))
{ $last = FALSE;
$message = '<P><FONT COLOR="red">You Need to enter your Last name!!</P></FONT>';
}
else {
$last = $_POST['last_name'];
}
if (empty($_POST['address']))
{ $add = FALSE;
$message = '<P><FONT COLOR="red">You Need to
enter your Address!!</P></FONT>';
}
else {
$add = $_POST['address'];
}
if (empty($_POST['email']))
{ $em = FALSE;
$message = '<P><FONT COLOR="red">You Need to
enter your Email Address!!</P></FONT>';
}
else {
$em = $_POST['email'];
}
}
if ($un && $pw && $first && $last && $add && $em)
{
//Register the user
require_once ('../mysql_connect.php');
//Database Query
$query = "INSERT INTO Customers (username, password, first_name, last_name, address, email, reg_date) VALUES ('$un', PASSWORD('$pw'), '$first', '$last', '$add', '$em', NOW())";
$result = @mysql_query ($query); //Execute
if ($result)
{
echo '<P><B>Congratulations you are now registered! <P>';
echo '<P><B>We have sent an Email to $em to confirm your registration details with us<P><P>';
include ('./footer.inc');
exit();
}
else
{
//If we get problems
$message = '<P><B>You could not be registered because of a system error.</P><P>' . mysql_error() . '</P>';
include ('./footer.inc');
}
mysql_close();
if (isset($message))
{
echo '<FONT COLOR="red">' , $message, '</FONT>';
}
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" METHOD="POST">
<TABLE WIDTH=200 ALIGN=center BORDER=0 CELLSPACING=10 CELLPADDING=15>
<TR>
<TD><B>Username :</TD>
<TD><INPUT TYPE="text" NAME="Username" SIZE="15" MAXLENGTH="40" value="<?php if (isset($_POST['username'])); ?>"></TD></TR>
<TR>
<TD><B>Password :</TD>
<TD><INPUT TYPE="password" NAME="password" SIZE="15" MAXLENGTH="20"></TD></TR>
<TR>
<TD><B>Re-type Password :</TD>
<TD><INPUT TYPE="password" NAME="confirmpass" SIZE="15" MAXLENGTH="20"></TD></TR>
<TR>
<TD><B>FirstName :</TD>
<TD><INPUT TYPE="text" NAME="first_name" SIZE="15" MAXLENGTH="40" value="<?php if (isset($_POST['first_name'])); ?>"></TD></TR>
<TR>
<TD><B>Surname :</TD>
<TD><INPUT TYPE="text" NAME="last_name" SIZE="15" MAXLENGTH="40" value="<?php if (isset($_POST['last_name'])); ?>"></TD></TR>
<TR>
<TD><B>Address :</TD>
<TD><TEXTAREA NAME="address" ROWS=5 COLUMNS=20 WRAP ALIGN="top" value="<?php if (isset($_POST['address'])); ?>"></TEXTAREA></TD></TR>
<TR>
<TD><B>Email :</TD>
<TD><INPUT TYPE="text" NAME="email" SIZE="40" MAXLENGTH="100" value="<?php if (isset($_POST['email'])); ?>"></TD></TR>
<TR><TD COLSPAN=2>
<FONT SIZE=2> <B>Please Check the box to indicate you have read and understood the <A HREF="terms.html" TARGET="_blank">Terms and Conditions</A>
of using Star Racing <INPUT TYPE="checkbox" NAME="terms" Value="checked"></TD></TR>
<TR>
<TD><INPUT TYPE="submit" VALUE="Register"></TD>
<TD><INPUT TYPE="reset" VALUE="Clear Form"></TD></TR>
</TABLE>
<?php include ('./footer.inc'); ?>