Jump to content

[SOLVED] My website.


JP128

Recommended Posts

Hey I have been creating a php website, and it is going well. I have a register/login, and now making a PM system.

 

http://jp128.mooo.com/

 

that is the site... if you have AIM, add me.. EvilBore or Stropfo, and tell me what you think otherwise just post it back here...

 

If you see anything that is wrong, I'd like to know =P

 

 

Thanks, John

Link to comment
Share on other sites

This topic should probably be in either the "Beta Test Your Stuff!" forum, or the "Website Critique" forum.

 

I left a ton of things blank on the register script, and it only gives me 1 error message, for one blank field. You should make it so it tells EVERYTHING that the user did wrong. You can do this by using an array and populating it with error messages, then looping through it with a foreach displaying them.

 

 

Link to comment
Share on other sites

Also it resets the ENTIRE form when it tells you the error...meaning the user has to go back and redo everything they just did.

 

Okay, I am finding a bunch of things now:

 

-When you retype your password, it doesn't check if it is the same as the first typed password.

-It doesn't check the year field in the DOB area, you need to check if it is proper format, length, numeric, etc.

-It doesn't check if the email they entered is valid.

Link to comment
Share on other sites

.... something is wrong with my javascript... it still submits the form, even when it isnt supposed to...

here is the javascript code..

 

<script language=javascript>
var check = 1;
function checkForm(){
if(document.register.firstname.value.length == 0){
alert("You forgot to fill out the first name textbox");
check = 0;
}
if(document.register.lastname.value.length == 0){
alert("You forgot to fill out the last name textbox");
check = 0;
}
if(document.register.email.value.length == 0){
alert("You forgot to fill out the email textbox");
check = 0;
}
if(document.register.year.value.length == 0){
alert("You forgot to fill out the year textbox");
check = 0;
}
if(document.register.username.value.length == 0){
alert("You forgot to fill out the username textbox");
check = 0;
}
if(document.register.password.value.length == 0){
alert("You forgot to fill out the password textbox");
check = 0;
}
if(document.register.password1.value.length == 0){
alert("You forgot to fill out the confirm password textbox");
check = 0;
}
if(document.register.password.value != document.register.password1.value){
alert("Your passwords do not match");
check = 0;
}
if(check == 1){
document.register.submit();
}

}
</script>

and, it goes through the check twice....

Link to comment
Share on other sites

<script language=javascript>

var check = 1;

function checkForm(){

if(document.register.firstname.value.length == 0){

alert("You forgot to fill out the first name textbox");

check = 0;

return false;

}

if(document.register.lastname.value.length == 0){

alert("You forgot to fill out the last name textbox");

check = 0;

return false;

}

if(document.register.email.value.length == 0){

alert("You forgot to fill out the email textbox");

check = 0;

return false;

}

if(document.register.year.value.length == 0){

alert("You forgot to fill out the year textbox");

check = 0;

return false;

}

if(document.register.username.value.length == 0){

alert("You forgot to fill out the username textbox");

check = 0;

return false;

}

if(document.register.password.value.length == 0){

alert("You forgot to fill out the password textbox");

check = 0;

return false;

}

if(document.register.password1.value.length == 0){

alert("You forgot to fill out the confirm password textbox");

check = 0;

return false;

}

if(document.register.password.value != document.register.password1.value){

alert("Your passwords do not match");

check = 0;

return false;

}

if(check != 1){

document.register.submit();

}

 

}

</script>

 

try that 1st thats better i guess  funny you lol :D :D :D :D :D :D :D :D :D :D :D

Link to comment
Share on other sites

hah... it might be funny, but making was a huge learning experience :). I have only made a dent in the php language... I want to learn a lot more =P.... I dont know a ton of javascript.. what does return false do??

Link to comment
Share on other sites

<script language=javascript>

var check = 1;

function checkForm(){

if(document.register.firstname.value.length == 0){

alert("You forgot to fill out the first name textbox");

check = 0;

return false;

}

if(document.register.lastname.value.length == 0){

alert("You forgot to fill out the last name textbox");

check = 0;

return false;

}

if(document.register.email.value.length == 0){

alert("You forgot to fill out the email textbox");

check = 0;

return false;

}

else if(document.register.year.value.length == 0){

alert("You forgot to fill out the year textbox");

check = 0;

return false;

}

else if(document.register.username.value.length == 0){

alert("You forgot to fill out the username textbox");

check = 0;

return false;

}

else if(document.register.password.value.length == 0){

alert("You forgot to fill out the password textbox");

check = 0;

return false;

}

else if(document.register.password1.value.length == 0){

alert("You forgot to fill out the confirm password textbox");

check = 0;

return false;

}

else if(document.register.password.value != document.register.password1.value){

alert("Your passwords do not match");

check = 0;

return false;

}

else

document.register.submit();

}

 

}

</script>

 

now that will do

Link to comment
Share on other sites

<script language=javascript>

var check = 1;

function checkForm(){

if(document.register.firstname.value.length == 0){

alert("You forgot to fill out the first name textbox");

check = 0;

return false;

}

else if(document.register.lastname.value.length == 0){

alert("You forgot to fill out the last name textbox");

check = 0;

return false;

}

else if(document.register.email.value.length == 0){

alert("You forgot to fill out the email textbox");

check = 0;

return false;

}

else if(document.register.year.value.length == 0){

alert("You forgot to fill out the year textbox");

check = 0;

return false;

}

else if(document.register.username.value.length == 0){

alert("You forgot to fill out the username textbox");

check = 0;

return false;

}

else if(document.register.password.value.length == 0){

alert("You forgot to fill out the password textbox");

check = 0;

return false;

}

else if(document.register.password1.value.length == 0){

alert("You forgot to fill out the confirm password textbox");

check = 0;

return false;

}

else if(document.register.password.value != document.register.password1.value){

alert("Your passwords do not match");

check = 0;

return false;

}

else{

document.register.submit();

}

 

}

</script>

 

try

Link to comment
Share on other sites

this is my whole function for the registry form.

 

function regForm(){
echo '
<script language=javascript>
var check = 1;
function checkForm(){
if(document.register.firstname.value.length == 0){
alert("You forgot to fill out the first name textbox");
check = 0;
return false;
}
else if(document.register.lastname.value.length == 0){
alert("You forgot to fill out the last name textbox");
check = 0;
return false;
}
else if(document.register.email.value.length == 0){
alert("You forgot to fill out the email textbox");
check = 0;
return false;
}
else if(document.register.year.value.length == 0){
alert("You forgot to fill out the year textbox");
check = 0;
return false;
}
else if(document.register.username.value.length == 0){
alert("You forgot to fill out the username textbox");
check = 0;
return false;
}
else if(document.register.password.value.length == 0){
alert("You forgot to fill out the password textbox");
check = 0;
return false;
}
else if(document.register.password1.value.length == 0){
alert("You forgot to fill out the confirm password textbox");
check = 0;
return false;
}
else if(document.register.password.value != document.register.password1.value){
alert("Your passwords do not match");
check = 0;
return false;
}
else{
document.register.submit();
}

}
</script>
';
echo"<form name='register' method=\"post\" action=\"\" onSubmit='checkForm();'>
<center>
<table border=\"1\">
<tr>
<td colspan=2><center>Register</center></td>
</tr>
<tr>
<td width=\"121\">First Name:</td>
<td width=\"172\"><input type=text name=firstname></td>
</tr>
<tr>
<td>Last Name:</td>
<td><input type=text name=lastname></td>
</tr>
<tr>
<td>E-mail:</td>
<td><input type=text name=email></td>
</tr>
<tr>
<td>Date of Birth: </td>
<td><select name=\"month\" id=\"month\">
  <option value=\"01\" selected>Jan</option>
  <option value=\"02\">Feb</option>
  <option value=\"03\">Mar</option>
  <option value=\"04\">Apr</option>
  <option value=\"05\">May</option>
  <option value=\"06\">Jun</option>
  <option value=\"07\">Jul</option>
  <option value=\"08\">Aug</option>
  <option value=\"09\">Sep</option>
  <option value=\"10\">Oct</option>
  <option value=\"11\">Nov</option>
  <option value=\"12\">Dec</option>
</select>
  <select name=\"day\" id=\"day\">
    <option value=\"01\" selected>01</option>
    <option value=\"02\">02</option>
    <option value=\"02\">03</option>
    <option value=\"04\">04</option>
    <option value=\"05\">05</option>
    <option value=\"06\">06</option>
    <option value=\"07\">07</option>
    <option value=\"08\">08</option>
    <option value=\"09\">09</option>
    <option value=\"10\">10</option>
    <option value=\"11\">11</option>
    <option value=\"12\">12</option>
    <option value=\"13\">13</option>
    <option value=\"14\">14</option>
    <option value=\"15\">15</option>
    <option value=\"16\">16</option>
    <option value=\"17\">17</option>
    <option value=\"18\">18</option>
    <option value=\"19\">19</option>
    <option value=\"20\">20</option>
    <option value=\"21\">21</option>
    <option value=\"22\">22</option>
    <option value=\"23\">23</option>
    <option value=\"24\">24</option>
    <option value=\"25\">25</option>
    <option value=\"26\">26</option>
    <option value=\"27\">27</option>
    <option value=\"28\">28</option>
    <option value=\"29\">29</option>
    <option value=\"30\">30</option>
    <option value=\"31\">31</option>
  </select>
  <input name=\"year\" type=\"text\" id=\"year\" size=\"5\" maxlength=\"4\"></td>
</tr>
<tr>
<td>Username:</td>
<td><input type=text name=username></td>
</tr>
<tr>
<td>Password:</td>
<td><input type=password name=password></td>
</tr>
<tr>
<td>Re-Type Password:</td><td><input type=password name=password1></td>
</tr>
<tr>
  <td><div align=\"right\">
    <input type='submit' value='Register'>
  </div></td>
  <td><input name=\"reset\" type=reset></td>
</tr>
  <tr>
    <td colspan='2'><div align='right'>©2006 John-Paul Ensign</div></td>
  </tr>
</table>



</center>
</form>";
exit;
}

Link to comment
Share on other sites

What would be a different way that I could validate the form? You've already seen the red text part, but what would you do to make it better?

 

Just asking for ideas, not an entire script.

 

form:

firstname

lastname

email

username

password

confirmpassword

 

those are the ones that I need to validate.

 

Link to comment
Share on other sites

You could store the error messages in an array.

 

<?php

if ($_POST['submit']){

   //Do all error checking like this
   if (empty(trim($firstname))) $error[] = "You need to put a first name!";
   if (empty(trim($lastname))) $error[] = "You need to put your last name!";
   if (empty(trim($email))) $error[] = "You need to put an email!";
   if (empty(trim($username))) $error[] = "You need to specify a username!";

     if (!empty($error)){

         foreach ($error as $message){
             echo '<li>'.$message.'</li>';
         }      
     } else {
        //Insert data into database, they filled the form out correctly.
     }
}

?>

Link to comment
Share on other sites

ok, I got that to work. I added in another page so that it doesnt refresh, and the users dont lose all the info that they did have typed, and I had to take out the empty(), because it gave me this error:

 

 

PHP Fatal error:  Can't use function return value in write context in...

 

 

I replaced it with length(trim()).

I also really like that way of error handling, I wouldn't have ever thought of that... it makes it very easy to add another kind of validation.

 

Thanks for your help, but still one more question.

 

How do I check to see that there are only numeric characters, and no alpha?

edit ... I used preg_match, and made my own pattern

 

here is the final register script:

<?php
function regAdd(){
dbConnect();

if (isset($_POST['submit'])){
   $pattern     = "/^(\d{4})$/";
   $year        = $_POST['year'];
   preg_match($pattern,$year,$match);
   $cur_year = date('Y');
   $firstname   = $_POST['firstname'];
   $lastname    = $_POST['lastname'];
   $username    = $_POST['username'];
   $email       = $_POST['email'];
   $password    = $_POST['password'];
   $password1   = $_POST['password1'];
   //Do all error checking like this
   if (strlen(trim($firstname)) == 0){ $error[1] = "You need to put a first name!"; }
   if (strlen(trim($lastname)) == 0){ $error[2] = "You need to put your last name!"; }
   if (strlen(trim($email)) == 0){ $error[3] = "You need to put an email!"; }
   if (strlen(trim($username)) == 0){ $error[4] = "You need to specify a username!"; }
   if (strlen(trim($password)) == 0){ $error[5] = "You need to specify a password!"; }
   if (strlen(trim($password1)) == 0){ $error[6] = "You need to confirm the password!"; }
   if (strlen(trim($year)) == 0){ $error[7] = "You need to specify a year!"; }
   if ($password != $password1){ $error[8] = "Your passwords didn't match!"; }
   if (!isset($match[1])){ $error[9] = $year." is not a valid year!"; }
   if ($year >= $cur_year){ $error[10] = "You cannot be born in the future!"; }
//   if (){ $error[] = ""; } //add another error
//   if (){ $error[] = ""; } //add another error
     if (!empty($error)){

         foreach ($error as $message){
             echo '<li>'.$message.'</li>';
   
         
         }      
         ?>
         <br>
         <title>Error while trying to register.</title>
         <button onClick='history.go(-1);'>Fill in the rest</button>
<?php
     } 
     else
     {
        echo "<title>Registered!</title>";
        $dob = $_POST['month'] . "-" . $_POST['day'] . "-" . $match[1];
        //Insert data into database, they filled the form out correctly.
        $sqlFind = mysql_query("SELECT ****,**** FROM **** WHERE ****='$****' OR ****='$****'");
        $numsqlFind = mysql_num_rows($sqlFind);
        if($numsqlFind > 0){
           echo"<font color=red><center><h3>That username, or email was already used, cannot continue!</h3></center></font>";
           regForm();
           exit;
         }
         else
         {
          mysql_query("insert into **** values('','$****','$****','$****,'$'****',****,'$****','****',****,'****','****','****','****','****')") or die(mysql_error());
          echo"Welcome, $firstname $lastname. Your username is $username. Your email is $email. <a href=http://jp128.mooo.com/login.php>Login</a>.";
          mysql_query("insert into **** values('','****','$username','Welcome!','Welcome to jp128.mooo.com.',null,'','')");
         }
      }
   }
}

?>

 

 

 

 

 

Thank you guys for all of your help... If you want to try to find more errors, just look, and if you see any just post back here so I can fix them... However for now, I will put SOLVED

Link to comment
Share on other sites

It's getting better =P

 

Now you need to check if the email is a valid format.

 

Also, for when you enter the year for the DOB, if I enter "sdfd", it will tell me I can't enter a date in the future, when the actual error is that I entered letters for the year. It also says something like "You would be dead if you were born then"....which is also not true.

 

Personally, I would put the errors ABOVE the form when it is submitted, instead of a separate page.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.