Jump to content

[SOLVED] Register page using $_POST


DeathStar

Recommended Posts

Hi there.

I made a register page but for some reson im getting this error:

Parse error: syntax error, unexpected T_ELSEIF in /home/deathsta/public_html/register.php on line 81

 

As normally you would think its a simple error like a missing ";" or "}", well its not(i think)

 

here is my code:

<?php
session_start();
mysql_connect('localhost','usr','pass') or die(mysql_error());
mysql_select_db('db');
function valid_email ($email)
{
  // First, we check that there's one @ symbol, and that the lengths are right
  if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email))
   {
    // Email invalid because wrong number of characters in one section, or wrong number of @ symbols.
    return false;
   }

  // Split it into sections to make life easier
  $email_array = explode("@", $email);
  $local_array = explode(".", $email_array[0]);

  for ($i = 0; $i < sizeof($local_array); $i++)
   {
    if (!ereg(
                 "^(([A-Za-z0-9!#$%&#038;'*+/=?^_`{|}~-][A-Za-z0-9!#$%&#038;'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$",
                 $local_array[$i]))
     {
      return false;
     }
   }

  if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1]))
   { // Check if domain is IP. If not, it should be valid domain name
    $domain_array = explode(".", $email_array[1]);

    if (sizeof($domain_array) < 2)
     {
      return false; // Not enough parts to domain
     }

    for ($i = 0; $i < sizeof($domain_array); $i++)
     {
      if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i]))
       {
        return false;
       }
     }
   }

  return true;
}
$title = $_SERVER['SCRIPT_NAME'];
print "<title>$title</title>
<style type='text/css'>
<!--
body {
background-color: #000000;
}
.style3 {color: #CCCCCC}
.style4 {color: #666666}
.style5 {color: #666666; font-weight: bold; }
-->
</style>
";
$numb = rand(1,4);
$number = "mogspam$numb.png";
print "<center><table border=3 bordercolor=white><tr><td><img src='$number'></td></tr></table><br />";
print "<div align='center'>";

if ($_POST){

  if (!valid_email($_POST['email']))
   {
    print "<font color=#ff0000>Sorry, the email is invalid.</font><br />
><a href='register.php'>Back</a>";
   }

  elseif (strlen($_POST['username']) < 4)
   {
    print "<font color=#ff0000>Sorry, the username you entered is too short.</font></font><br />
><a href='register.php'>Back</a>";
   }

$q2 = mysql_query("SELECT * FROM users WHERE email='{$_POST['email']}'");
elseif ($q2)
   {
    print "<font color=#ff0000>E-Mail already in use. Choose another.</font><br />
><a href='register.php'>Back</a>";

   }

  else
   {
    $IP           = ($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
     
     /* We ensure that somebody has not signed up from this IP in the last 2 hrs = 2 * 60 * 60 = 7200 secs */
     
     $chk_ip_dup = mysql_query("SELECT * FROM users WHERE ip_signup='{$IP}'");
     if (mysql_num_rows($chk_ip_dup))
     {
          print "<b><font color=red size=+1>Naugthy, naughty! Moderator advised!</font></b></body></html>";

     }
    // define possible characters
    $possible = "0123456789bcdfghjkmnpqrstvwxyz"; 
    
    // set up a counter
    $i = 0; 
    
    // add random characters to $password until $length is reached
    while ($i <  { 

      // pick a random character from the possible ones
      $char = substr($possible, mt_rand(0, strlen($possible)-1), 1);
        
      // we don't want this character if it's already in the password
      if (!strstr($userpass, $char)) { 
        $password .= $char;
        $i++;
      }

    }
$md5password = md5($password);
$usernameconv = $_POST['username'];
$email = $_POST['email'];

    mysql_query("INSERT INTO `users` (`name` , `password` , `email` , `ip_login` , `ip_signup` , `verified` , `verified_code` )
VALUES ('$usernameconv', '$md5password', '$email', '127.0.0.1', '$IP', '0', '$md5password')");

$to      = '$email';
$subject = 'Acount Reminder';
$message = 'Hello there, Just a reminder that your password is: $password';
$headers = 'From: webmaster@noreply.com' . "\r\n" .
   'Reply-To: webmaster@noreply.com' . "\r\n" .
   'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

    	print "<center><font color=white><b>Your Signup was processed sucessfully!!<b><br>";
        print "Your password is: \"$password\"<b><br>";
        print "You are now able to <a href='login.php'>Login</a></font>"; }}
}

print "<table width='415' height='210' border='0' cellpadding='0' cellspacing='0'>
    <tr><form action='register.php' method='post'>
      <td width='33'> </td>
      <td width='33'> </td>
      <td width='127'><div align='center' class='style5'>
        <table width='1' border='0' cellpadding='0' cellspacing='0' bordercolor='#333333'>
          <tr>
            <td> <font color=#CCCCCC><b>Username: </td>
          </tr>
        </table>
      </div></td>
      <td width='160'><div align='center' class='style4'>
        <table width='1' border='1' cellpadding='0' cellspacing='0' bordercolor='#333333' name='tabel'>
          <tr>
            <td><input name='username' type='text' style='background-color:#333333;border-bottom-color:#595B56;border-top-color:#595B56;border-right-color:#595B56;border-left-color:#595B56;border-bottom-style:none;border-top-style:none;border-right-style:none;border-left-style:none;color:#CCCCCC' onclick='tabel.bordercolor='red'' size='15'/></td>
          </tr>
        </table>
      </div></td>
      <td width='33'><span class='style4'></span></td>
      <td width='33'> </td>
    </tr>
    <tr>
      <td> </td>
      <td> </td>
      <td><div align='center' class='style5'>
        <table width='1' border='0' cellpadding='0' cellspacing='0' bordercolor='#000000'>
          <tr>
            <td><font color=#CCCCCC><b>Email:</td>
          </tr>
        </table>
        </div></td>
      <td><div align='center' class='style4'>
        <table width='1' border='1' cellpadding='0' cellspacing='0' bordercolor='#000000'>
          <tr>
            <td><input name='email' type='text' style='background-color:#333333;border-bottom-color:#595B56;border-top-color:#595B56;border-right-color:#595B56;border-left-color:#595B56;border-bottom-style:none;border-top-style:none;border-right-style:none;border-left-style:none;color:#CCCCCC' size='15'/></td>
          </tr>
        </table>
      </div></td>
      <td><span class='style4'></span></td>
      <td><div align='center'></div>
        <div align='center'></div></td>
    </tr>
    <tr>
      <td><div align='center'></div></td>
      <td><div align='center'></div></td>
      <td><div align='center'>

        <input type='submit' value=' Register ' style='background-color:#333333;border-bottom-color:#FFFFFF;border-top-color:#FFFFFF;border-right-color:#FFFFFF;border-left-color:#FFFFFF;color:#CCCCCC'  />
      </div></td>
      <td><div align='center'>
        <input type='reset' value=' Reset ' style='background-color:#333333;border-bottom-color:#FFFFFF;border-top-color:#FFFFFF;border-right-color:#FFFFFF;border-left-color:#FFFFFF;color:#CCCCCC' /></form>
      </div></td>
      <td><div align='center'></div></td>
      <td><div align='center'></div></td>
    </tr>
    <tr>
      <td><div align='center'></div></td>
      <td><div align='center'><span class='style4'></span></div></td>
      <td> </td>
      <td> </td>
      <td><div align='center'><span class='style3'><span class='style4'></span></span></div></td>
      <td><div align='center'></div></td>
    </tr>
  </table>
</div>
<h1 align='center' class='style5'><a href='login.php' class='style4'Login</a></h1>";

print "</td></tr></table>";
?>

Link to comment
Share on other sites

it may be because your line--> elseif (strlen($_POST)) is also false??, ive had this happen to me, but cant quite remember how I got around it?, maybe try else insted of elseif`s???.

 

The elseif statement is only executed if the preceding if expression and any preceding elseif expressions evaluated to FALSE, and the current elseif expression evaluated to TRUE
Link to comment
Share on other sites

elseif ($q2)

thats refering to:

$q2 = mysql_query("SELECT * FROM users WHERE email='{$_POST['email']}'");
elseif ($q2)
   {
    print "<font color=#ff0000>E-Mail already in use. Choose another.</font><br />
><a href='register.php'>Back</a>";

   }

Link to comment
Share on other sites

Ok, im not pretty good in php, but based on the programmations basics, to call an elseif, you need a comparison but with your

$q2 = mysql_query("SELECT * FROM users WHERE email='{$_POST['email']}'")

your simply setting up an array

so $q2 is not a test at all, its a list of all the emails equal to $_POST['email']

If you could select the first(cuz your not supposed to have more than one) array of this list and test it with $_POST, it should work

 

again, sorry, if this is totally wrong, I usually do vbasic, not php

 

 

Link to comment
Share on other sites

Please note: "Topic Solved".

 

The problems That I have corrected is:

$q2 = mysql_query("SELECT * FROM users WHERE email='{$_POST['email']}'");
if (mysql_fetch_row($q2))
   {
    print "<font color=#ff0000>E-Mail already in use. Choose another.</font><br />
><a href='register.php'>Back</a>";

   }

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.