Registration script issues

I’m having problems with a code I am trying to make.
[php]

<?php /* Functions in this file */ /**************************/ // login() // register() // register_form() ?> <?php ini_set ("display_errors", "1"); error_reporting(E_ALL); function register() { include "connect.php"; $con = mysql_connect($host, $uname, $pass) or die(mysql_error()); mysql_select_db($dbname, $con) or die(mysql_error()); $username = trim($_POST['username']); $password = trim($_POST['password']); $pass_conf = trim($_POST['pass_conf']); $email = trim($_POST['email']); //Check the Data if (empty($username)) { die ("Fill in a username!"); } if (empty($password)) { die ("You forgot to fill in a password!"); } if (empty($pass_conf)) { die ("Confirm your password"); } if (empty($email)) { die ("We can't register you without an email"); } $patt = "^[A-Za-z1-9 _-]+$"; if (!ereg($patt, $username)) { die("Invalid characters in your username"); } if (!ereg($patt, $password)) { die("Invalid characters in your password"); } if (!ereg("^.+@.+$", $email)) { die ("Invalid email format."); } if ($password != $pass_conf) { die ("The two passwords do not match!"); } //Check to see if username is in use already. $sql = mysql_query("SELECT username from users WHERE username = '".$username."'") or die(mysql_error()); $num_rows = mysql_num_rows($sql); if ($num_rows > 0) { die ("Username already exists!"); } //Check to see if email is in use or not. $sql2 = mysql_query("SELECT email from users WHERE email = '".$email."'") or die (mysql_error()); $num_rows2 = mysql_num_rows($sql2) or die(mysql_error()); if ($num_rows2 > 0) { die ("E-mail is in use!"); } else { $new_pass = md5($password); $query = "INsERT INTO users (username, password, email) values ('".$username."', '".$new_pass."', '".$email."')"; $mysql = mysql_query($query) or die (mysql_error()); if ($mysql) { die("Works"); } elseif(!$mysql) { die (mysql_error()); } $_SESSION['status'] = "Loggedin"; $_SESSION['username'] = $username; $message = "Welcome, ".$username."You are now logged in. Log in"; echo $message; } } function register_form() { echo " Please register below
Username
Password:
Confirm your password:
E-mail:
"; } function login() { header("Location: index.php"); } switch($_GET['act']) { case "register": register(); break; case "login": login(); break; default: register_form(); } ?>

[/php]
I know that the switch works because it goes through and checks all the information. However, right after it checks to see if a username or email already exists, it completely stops working. Does anyone know why?

Sounds like a Control Flow problem. Try tracing the problem by echoing stuff. I use checkpoints like that when debugging control flow issues:

[php]echo “CheckPoint 1”;[/php]

Use increasing numbers to avoid confuzion though :slight_smile: You should be able to trace the bug that way.

Sponsor our Newsletter | Privacy Policy | Terms of Service