Jump to content

register prob


S A N T A

Recommended Posts

k this register code wont work wahts up?

 

<?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 {

	for($i = 0; $i < 16; $i++) {
		$randomstring .= chr(mt_rand(32,126));
		}

		$verifyurl = "http://localhost/verify.php";
		$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);";
		mysql_query($sql)or die(mysql_error());
		require("header.php");
		}
		else {
			header("Location: " . $config_basedir . "reg.php?error=pass");
		}
		else {

			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; ?>, filll 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
}

require("footer.php");

?>

 

thanks in advance

Link to comment
Share on other sites

<?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 {

 

for($i = 0; $i < 16; $i++) {

$randomstring .= chr(mt_rand(32,126));

}

 

$verifyurl = "http://localhost/verify.php";

$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);";

mysql_query($sql)or die(mysql_error());

require("header.php");

}

else {

header("Location: " . $config_basedir . "reg.php?error=pass");

}

else {

 

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; ?>, filll 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

}

 

require("footer.php");

 

?>

 



 

Replace this block

 

else {

 

for($i = 0; $i < 16; $i++) {

$randomstring .= chr(mt_rand(32,126));

}

 

$verifyurl = "http://localhost/verify.php";

$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);";

mysql_query($sql)or die(mysql_error());

require("header.php");

}

else {

header("Location: " . $config_basedir . "reg.php?error=pass");

}

else {

 

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;

 

}

 


 

WITH

 

else {

 

for($i = 0; $i < 16; $i++) {

$randomstring .= chr(mt_rand(32,126));

}

 

$verifyurl = "http://localhost/verify.php";

$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");

}

elseif(!$query) {

header("Location: " . $config_basedir . "reg.php?error=pass");

}

elseif(!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;

 

}

 

 

Have a go with that fella, its really hard to debug this script its laid out a bit rough xD good luck though mate

 

Link to comment
Share on other sites

ok so i tried changing the code to

 

<?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 {
   
      for($i = 0; $i < 16; $i++) {
         $randomstring .= chr(mt_rand(32,126));
         }
         
         $verifyurl = "http://localhost/verify.php";
         $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");
         }
	 }
         if(!$query) {
            header("Location: " . $config_basedir . "reg.php?error=pass");
        

         if(!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;
               
            }

 

and i got

 

Parse error: syntax error, unexpected $end in C:\xampp\htdocs\reg.php on line 54

Link to comment
Share on other sites

Have you made any real effort to figure out why this isn't working yourself?  Or are you just looking for copy and paste solutions?

 

Whenever you have a syntax error, you can always, always figure out where the error is by commenting out chunks of code at a time.  This is where a good editor's automatic commenting (usually ctrl + /) comes in handy.

 

Start around where the error is reported.  Start at the most nested piece of code and comment it out.  If you get the error move up on level on your indentation and comment that section.  Repeat until the error goes away.

 

It's repetitive but you can find the error that way.  Also, syntax errors will always come up in coding so you might as well learn how to fix them yourself now.

Link to comment
Share on other sites

ok so i fixed the error:

 

<?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 {
   
      for($i = 0; $i < 16; $i++) {
         $randomstring .= chr(mt_rand(32,126));
         }
         
         $verifyurl = "http://localhost/verify.php";
         $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");
         }
         if(!$query) {
            header("Location: " . $config_basedir . "reg.php?error=pass");
         }
         if(!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; ?>, filll 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
}
}
}


require("footer.php");

?>

 

but now the form doesn't display

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.