Hi i'm trying to make a page that will create a new user account into my mysql database. I know the psuedo code that must be performed i'm just haveing problems putting it into php.
When the user clicks submit
1. The username and email address provided must be checked not to be null and longer than 6 characters.
- The username and email address must both be checked against the database to make sure that neigther already exist.
3a. (if email/user not present)The account must be inserted into the database and a password for them randomly generate.
4a. (if email/user not present)The new password should be displayed to the user along with a success message.
3b. (if email/user is present)an error messsage must be displayed to the user saying account exists.
seems simple enough but i'm having some real trouble getting the code lined out as i'm new to php. Here is what i've been able to piece together from some tutorials/examples so far.
<center>
<table width="100%" border="1" cellspacing="0" cellpadding="1" valign=top>
<form method="post" action="<?php echo $PHP_SELF?>">
<tr><td bgcolor="darkgray"><p>Username:</p></td><td align=center><input type="Text" name="uname"></td></tr>
<tr><td bgcolor="darkgray"><p>Email Address (must be valid):</p></td><td align=center><input type="Text" name="address"></td></tr>
</table>
<br><input type="Submit" name="submit" value="Create Account">
</form>
<?php
if ($submit) {
$db = mysql_connect("localhost", "root");
mysql_select_db("basementIM",$db);
echo "<br><p><font color=red>Submitting!</font></p>";
$sql = "SELECT Count(*) FROM Accounts WHERE Username='$uname' OR Email='address'";
$result = mysql_query($sql);
if ($result='0') {
$newpass=Random_Password(8);
$sql = "INSERT INTO Accounts (Username, Password, Email, Active) VALUES ('$uname', password('$newpass'),'$address',1)";
$result = mysql_query($sql);
echo "Account created!<br> Your username is: $uname <br> Your password is: $newpass<p>";
} else {
echo "<br><p><font color=red>Account username/email already exists!</font></p>";
}
}
?>
<?php
function Random_Password($length) {
srand(date("s"));
$possible_charactors = "ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890";
$string = "";
while(strlen($string)<$length) {
$string .= substr($possible_charactors,(rand()%(strlen($possible_charactors))),1);
}
return($string);
}
?>
</center>
im seeing two main problems with this code.. #1 i'm getting the submitting and account exists message when i first go to the page.. and upon clicking submit no new records are ever posted.
If someone would help me work through this, or post a link to a simlar code example i'd really appreciate it.
Thanks
Discord(ultra PHP noob)