Jump to content

Register problem


S A N T A

Recommended Posts

I am building a registration page for my blog i am making but for some reason it is not working. It all works and its nice on mozila firefox (Exept my antire website gets all screwed up when i view it in firefox) but in internet explorer i click "Register" and it gives me the 404 error ( Internet Explorer cannot display the webpage )

 

here is the registration code:

<?php

session_start();

require("config.php");

$db = mysql_connect($dbhost, $dbuser);
mysql_select_db($dbdatabase, $db);

if($_POST['submit']) {
   if($_POST['password'] == $_POST['password2']) {
      $checksql = "SELECT * FROM user WHERE username = '" . $_POST['username'] . "';";
      $checkresult = mysql_query($checksql)or die(mysql_error());
      $checknumrows = mysql_num_rows($checkresult);

if($checknumrows == 1) {
   header("Location: " . $config_basedir . "reg.php?error=taken");
   }
   
else {
   echo "Thank you for registering";
      for($i = 0; $i < 16; $i++) {
         $randomstring .= chr(mt_rand(32,126));
         }
         
         
         $verifystring = urlencode($randomstring);
         $validusername = $_POST['username'];
         
         $sql = "INSERT INTO user(username, password, name, lastname) VALUES('" . $_POST['username'] . "', '" . $_POST['password'] . "' '" . $_POST['name'] . "' '" . $_POST['lastname'] . "' '" . addslashes($randomstring) . "', 0);";
         $query = mysql_query($sql)or die(mysql_error());
         require("header.php");
         }
         else(!$query) {
            header("Location: " . $config_basedir . "reg.php?error=pass");
         }
         else(!empty($_GET['error'])){
         
            require("header.php");
            
            switch($_GET['error']) {
            case "pass":
               echo "Passwords do not match!";
               break;
            case "taken":
               echo "Username taken, please use another.";
            break;
               case "no":
                  echo "Incorect login details!";
               break;
               
            }



         
?>
<h2>Register</h2>
To register on <?php echo $config_blogname; ?>, fill out the form below.
<form action="<?php echo $SCRIPT_NAME ?>" method="POST">
<table>
<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="password2"></td>
</tr>
<tr>
   <td>First Name</td>
   <td><input type="text" name="name"></td>
</tr>
<tr>
   <td>Last Name</td>
   <td><input type="text" name="lastname"></td>
</tr>
<tr>
   <td></td>
   <td><input type="submit" value="Register!"></td>
</tr>
</table>
</form>
<?php
}
}
}

echo "CHEEZ";
require("footer.php");

?>

 

All help appreciated!

 

EDIT:

 

Ok i dont know what i did but now i get this error:

Parse error: syntax error, unexpected T_ELSE in "!!MY FILE!!" on line 34

 

Link to comment
https://forums.phpfreaks.com/topic/131854-register-problem/
Share on other sites

$sql = "INSERT INTO user(username, password, name, lastname) VALUES('" . $_POST['username'] . "', '" . $_POST['password'] . "' '" . $_POST['name'] . "' '" . $_POST['lastname'] . "' '" . addslashes($randomstring) . "', 0);";
         $query = mysql_query($sql)or die(mysql_error());
         require("header.php");
         }
         else(!$query) {
            header("Location: " . $config_basedir . "reg.php?error=pass");
         }
         else(!empty($_GET['error'])){
         
            require("header.php");
            

 

You have else statements without any IF statements?

 

IF

ELSE IF

ELSE

Link to comment
https://forums.phpfreaks.com/topic/131854-register-problem/#findComment-684957
Share on other sites

This:

 


$sql = "INSERT INTO user(username, password, name, lastname) VALUES('" . $_POST['username'] . "', '" . $_POST['password'] . "' '" . $_POST['name'] . "' '" . $_POST['lastname'] . "' '" . addslashes($randomstring) . "', 0);";
         $query = mysql_query($sql)or die(mysql_error());
         require("header.php");
         }
         else(!$query) {
            header("Location: " . $config_basedir . "reg.php?error=pass");
         }
         else(!empty($_GET['error'])){
         
            require("header.php");

 

Should be this:

 


$sql = "INSERT INTO user(username, password, name, lastname) VALUES('" . $_POST['username'] . "', '" . $_POST['password'] . "' '" . $_POST['name'] . "' '" . $_POST['lastname'] . "' '" . addslashes($randomstring) . "', 0);";
         $query = mysql_query($sql)or die(mysql_error());
         require("header.php");
         }
         elseif (!$query) {
            header("Location: " . $config_basedir . "reg.php?error=pass");
         }
         elseif(!empty($_GET['error'])){
         
            require("header.php");

Link to comment
https://forums.phpfreaks.com/topic/131854-register-problem/#findComment-685136
Share on other sites

Archived

This topic is now archived and is closed to further replies.

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