Jump to content

pottrell

New Members
  • Posts

    9
  • Joined

  • Last visited

pottrell's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. I'm not sure how you mean, if I moved it below the $user_name($_POST how would i begin the statement to include the query? :/
  2. <?php $host = 'localhost'; $user = '#########'; $password = '#########'; $database = '#########'; $conn = mysql_connect($host,$user,$password) or die('Database Information incorrect'); //Establish connection with database and error message mysql_select_db($database,$conn); //$conn = mysql_connect("localhost", "pottrell", "dp089786+"); //mysql_select_db("pottrell_wrdp1"); if (isset($_POST['submitted'])) { // set errors equal to 0 $error = "0"; $query = "SELECT * FROM `table` WHERE `username` = '$user_name'"; $result = mysql_query($query); $num = mysql_num_rows($result); if($num != "0") { echo "That username already exists<br />"; $error = "1"; } elseif (empty($_POST['user_name'])) { echo 'Please Enter a username<br />'; $error = "1"; } else { $user_name = mysql_real_escape_string($_POST['user_name']); } if (empty($_POST['password'])) { echo 'Please enter a password<br />'; $error = "1"; } else { $password = mysql_real_escape_string($_POST['password']); } if (empty($_POST['first_name'])) { echo 'Please enter a first name<br />'; $error = "1"; } else { $first_name = mysql_real_escape_string($_POST['first_name']); } if (empty($_POST['last_name'])) { echo 'Please enter a last name<br />'; $error = "1"; } else { $last_name = mysql_real_escape_string($_POST['last_name']); } $day = mysql_real_escape_string($_POST['day']); $month = mysql_real_escape_string($_POST['month']); $year = mysql_real_escape_string($_POST['year']); $date = getDate(); $tday = $date["mday"]; $tmon = $date["mon"]; $tyea = $date["year"]; $sixteen = (($tyea - 16)*10000) + ($tmon*100) + $tday; $dd = $_POST["dob_day"]; $mm = $_POST["dob_month"]; $yy = $_POST["year"]; $dob = ($yy*10000) + ($mm*100) + $dd; if($dob>= $sixteen) { echo "User must be over the age of 16."; $error = "1"; } // Check if error = 0 if($error == "0") { $query = "insert into user(user_name,password,first_name,last_name,day,month,year)values('$user_name','$password','$first_name','$last_name','$day','$month','$year')"; $res = mysql_query($query); echo "<br/><br/>"; echo "Sign up successful - Thank you $first_name <br/>"; echo "Your details are as follows:<br/><br/>"; echo "<strong>Username:</strong> $user_name<br/>"; echo "<strong>First name:</strong> $first_name<br/>"; echo "<strong>Last name:</strong> $last_name<br/>"; echo "<strong>Password:</strong> <i>[Hidden]</i>:<br/>"; echo "<strong>Date of Birth:</strong> $day / $month / $year<br/>"; } } ?> So close to getting it to work completely! The issue at the moment is the no matter what the user enters, it returns "That username already exists" Am I thinking about the if else statement the wrong way?
  3. Would that appear after "if (isset($_POST['submitted']))" or before? I can see how this would work at least! Thanks
  4. Strange! I just recreated the table and now it works! The last thing I need to try to do is to ensure the username is unique. Do you know of any tutorials I could follow to try and do this if possible? All I know is it would involve connecting to the database, looking for the same username as what is entered and returning true or false... :/
  5. Aha! Perfect! I've just tested it all, there's one mystery now, it's suddenly stopped writing to the database, i've checked all the details and they're all correct, weird! Thanks again though, the error messages appear perfectly
  6. In that case (your latest example). Is there a way to use the method of ensuring the user is over 16 like i had before? I've tried to use your latest code and apply it to the method but failed, badly Thanks again for this! Even if you can't help me further, you've been a great help!
  7. Oops! (again) - I changed my password etc, my bad. That works great, with regards to the password, do you mean using md5? Also, is there anyway to ensure the error messages are ordered? Or combine the code so the date of birth will return inside the same error messages being used by the other validation rules? So If i left Username empty and password empty as well as the birthday - It will present the error message "Please fill in a username" "Please fill in a password" "Please fill in your date of birth" Would this involve too much change from the original code? Many thanks again, I understand this to an extent, just those little subtle errors throw me..
  8. Oops! Thanks for pointing that out! I'm not actually sure how to print the errors unfortunately!
  9. I'm trying to get my form to print an error message when the user doesn't input a username, first name, password etc (will get to the others eventually). This is what I've managed to do by myself so far, but I'm at a loss as to why it's not working now <?php $host = 'localhost'; $user = ''; $password = ''; $database = ''; $conn = mysql_connect($host,$user,$password) or die('Database Information incorrect'); //Establish connection with database and error message mysql_select_db($database,$conn); //$conn = mysql_connect("localhost", "pottrell", "dp132435"); //mysql_select_db("pottrell_wrdp1"); if (isset($_POST['submitted'])) { $error = array(); if (empty($_POST['user_name'])) { $error[] = 'Please Enter a username';} else {$user_name = mysql_real_escape_string($_POST['user_name']);} if (empty($_POST['password'])) { $error[] = 'Please enter a password';} else {$password = mysql_real_escape_string($_POST['password']);} if (empty($_POST['first_name'])) { $error[] = 'Please enter a first name';} else {$first_name = mysql_real_escape_string($_POST['first_name']);} $last_name = mysql_real_escape_string($_POST['last_name']); $day = mysql_real_escape_string($_POST['day']); $month = mysql_real_escape_string($_POST['month']); $year = mysql_real_escape_string($_POST['year']); $date = getDate(); $tday = $date["mday"]; $tmon = $date["mon"]; $tyea = $date["year"]; $sixteen = (($tyea - 16)*10000) + ($tmon*100) + $tday; $dd = $_POST["dob_day"]; $mm = $_POST["dob_month"]; $yy = $_POST["year"]; $dob = ($yy*10000) + ($mm*100) + $dd; if ($dob >= $sixteen) { echo "Age Error"; } else if (empty($error)) { $query = "insert into user(user_name,password,first_name,last_name,day,month,year)values('$user_name','$password','$first_name','$last_name','$day','$month','$year')"; $res = mysql_query($query); echo "Sign up successful - Thank you $first_name <br/>"; echo "Your details are as follows:<br/><br/>"; echo "<strong>Username:</strong> $user_name:<br/>"; echo "<strong>First name:</strong> $first_name:<br/>"; echo "<strong>Last name:</strong> $last_name:<br/>"; echo "<strong>Password:</strong> <i>[Hidden]</i>:<br/>"; echo "<strong>Date of Birth:</strong> $day / $month / $year:<br/>"; } } //header('location:signup_success.php'); ?> Can anyone help me with this?
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.