here ya go..........
to answer your questions:
-- the query runs even if no $uname has been entered, but it returns as an empty set (bec. it's empty). the mysql error msg is present at this point.
-- the query runs even if $uname has been entered, but the mysql error msg is still present at -- $num = mysql_numrows($result); --
-- for some stupid reason i'm getting the feeling that this is going to give me header errors too --
--- i'll tell you what. if you help me figure this out, i will owe you a huge one, you name it ---
Code:
<?php
$DBhost = "localhost";
$DBuser = "xxxxxxxx";
$DBpass = "xxxxxxxxxx";
$DBName = "xxxxxxxxxxx";
$table = "xxxxxxx";
$db = mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");
//Start Error Message
$errorMsg = "<TABLE ALIGN=center BORDER=0><TR><TD>\n";
$errorMsg .= "<FONT COLOR=red size=\"2\">Error!</FONT>\n";
$errorMsg .= "<FONT COLOR=red>Unable to send your message because of the following empty field(s):\n<UL>";
$errorMsgEnd = "</UL>\nPlease enter the required information and resend.</FONT>\n";
$errorMsgEnd .= "</TD></TR></TABLE>\n";
//End Error Message
//Start Form Block
$formblock = "
<FORM METHOD=POST ACTION=\"/php-bin/register1.php\">
<TABLE width=\"250\" height=\"250\" cellpadding=\"0\" cellspacing=\"0\" border=\"0\">
<TR>
<TD>
<div align=\"center\"><FONT FACE=\"ARIAL\" SIZE=\"-1\">User Name</FONT></div>
</TD>
<TD>
<INPUT TYPE=\"text\" NAME=\"uname\" size=\"20\" VALUE=\"$uname\"maxlength=\"20\">
</TD>
</TR>
<TR>
<TD>
<div align=\"center\"><font face=\"Arial, Helvetica, sans-serif\" size=\"-1\">Password</font></div>
</TD>
<TD>
<INPUT TYPE=\"password\" NAME=\"upass\" size=\"20\" VALUE=\"$upass\"maxlength=\"20\">
</TD>
</TR>
<TR>
<TD>
<div align=\"center\"><font size=\"-1\" face=\"Arial, Helvetica, sans-serif\">Confirm<br>
Password</font> </div>
</TD>
<TD>
<input type=\"password\" name=\"upass2\" size=\"20\" VALUE=\"$upass2\"maxlength=\"20\">
</TD>
</TR>
<TR>
<TD>
<div align=\"center\"><font face=\"Arial, Helvetica, sans-serif\" size=\"-1\">E-mail</font></div>
</TD>
<TD>
<input type=\"text\" name=\"Email\" size=\"20\" VALUE=\"$Email\"maxlength=\"40\">
</TD>
</TR>
<TR>
<TD COLSPAN=2>
<div align=\"center\">
<input type=\"hidden\" name=\"op\" value=\"ds\">
<input type=\"image\" src=\"/01/images/btn5b.gif\" width=\"44\" height=\"17\" alt=\"Send\" border=\"0\" align=\"absmiddle\" name=\"submit\">
</div>
</TD>
</TR>
<TR>
<TD COLSPAN=2></TD>
</TR>
</TABLE>
</FORM>
";
//End Form Block
//Start ErrorCheck
<!-- Note: the op variable will not equal anything until the form is submitted, none of the variables will -->
// they need to see the form
if ($op != "ds") {
echo "$formBlock";
} else if ($op == "ds") {
$send = "yes";
// check each required field and create an error message.
// if any of the required fields are blank, set $send to "no".
if ($upass == $upass2) {
$db = mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");
$sql = "SELECT * FROM $table WHERE uname='$uname'";
print $sql;
$result = mysql_query("SELECT * FROM $table WHERE uname='$uname'");
}
$num = mysql_num_rows($result);
//$result = mysql_query($sql,$db);
//}
//$num = mysql_num_rows($result);
if ($num != "0") {
$upassError3 = "<LI>The User Name you selected is already taken</LI>\n";
$send = "no";
}
}
if ($uname == "") {
$unameError = "<LI>User Name</LI>\n";
$send = "no";
}
if ($upass == "") {
$upassError = "<LI>Password</LI>\n";
$send = "no";
}
if ($Email == "") {
$EmailError = "<LI>E-mail</LI>\n";
$send = "no";
}
if ($upass != $upass2) {
$upassError2 = "<LI>Your Two Passwords Did Not Match</LI>\n";
$send = "no";
}
//End ErrorCheck
// now do something depending value of $send
if ($send == "yes") {
//select the DB
@mysql_select_db("$DBName") or die("Unable to select database $DBName");
//insert the values into the Db
$sqlquery = mysql_query("INSERT INTO $table VALUES('$uname','$upass','$Email')");
Header("Location: /01/html/resrc.html");
}
else if ($send == "no") {
echo "$errorMsg";
echo "$upassError3";
echo "$unameError";
echo "$upassError";
echo "$EmailError";
echo "$upassError2";
echo "$errorMsgEnd";
echo "$formblock";
}
?>
Bookmarks