Eggzorcist Posted October 2, 2008 Share Posted October 2, 2008 I made a script in which registrates a user very basicly. here are the functions used. I click submit get no error but it doesnt do anything to the databse nor does it send me the the url as indicated in the header(); <?php require_once('config.php'); function secure_var($var){ $var = mysql_real_escape_string(htmlentities($var)); } function check_username($username){ $query = mysql_query("SELECT * FROM user_info WHERE username = {$username}"); if ($query >= 1){ return true; } else { return false; } } function check_email($email){ $query = mysql_query("SELECT * FROM user_info WHERE email = {$email}"); if ($query >= 1){ return true; } else { return false; } } // Register User function register_user($username, $password1, $password2, $email, $captcha){ secure_var($username); secure_var($password1); secure_var($password2); secure_var($email); $Error = null; // Validate Username Field if(!preg_match("/\A[a-z0-9_]{4,15}$/i",$username)){ $Error .= "Username Can Only Contain Letters, Numbers and Underscores (Between 4-15 Characters Long) <br />"; } // Validates Username Availability if(check_username($username) == true){ $Error .= "You're chosen username is taken. Plase choose another one.<br />"; } // Validates Email Availability if (check_email($email) == true){ $Error .= "You're email is already in use.<br />"; } // Validate Password Field if (!preg_match("/\A[a-z0-9 _-]{4,15}$/i",$password1)){ $Error .= "Password Can Only Contain Letters, Numbers, And Underscores (Between 4-15 Characters Long <br />"; } // Validate Password Confirmation if ($password1 != $password2){ $Error .= "Password and Password Confirmation Do Not Match <br />"; } // Validate Email Address Format if (!preg_match("/\A[^0-9][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[@][a-zA-Z0-9_]+([.][a-zA-Z0-9_]+)*[.][a-zA-Z]{2,4}$/", $email)){ $Error .= "Email Address Must Be In format: [username]@[domain].[extension] <br />"; } // Validate Security Image if ($captcha != $_SESSION['captcha']){ $Error .= "Your Captcha Input Does Not Match The Image Shown"; } // Result Success or Error if($Error == null){ $reg_user = mysql_query("INSERT INTO user_info (username, password, email) VALUES ($username, $password, $email)"); if($reg_user){ header('login.php?reg=1'); } }else{ // Echo the error(s) echo($Error); } } ?> Quote Link to comment Share on other sites More sharing options...
JasonLewis Posted October 2, 2008 Share Posted October 2, 2008 The first things that I noticed were that you are checking to see if the query is greater than or equal to 1. mysql_query() returns a result resource. You need to perform mysql_num_rows() on the query then check if that is greater than or equal to 1, or just greater than 0. Quote Link to comment Share on other sites More sharing options...
waynew Posted October 2, 2008 Share Posted October 2, 2008 function check_email($email){ $query = mysql_query("SELECT * FROM user_info WHERE email = {$email}"); if (mysql_num_rows($query) >= 1){ return true; } else { return false; } } Fixed. Quote Link to comment Share on other sites More sharing options...
Eggzorcist Posted October 2, 2008 Author Share Posted October 2, 2008 alright thanks. However there is a pretty big issue near the end where it checks if theres no error and then it doesnt seem to do the header nor input the info to the database even if theres no error... Quote Link to comment Share on other sites More sharing options...
MasterACE14 Posted October 2, 2008 Share Posted October 2, 2008 add error_reporting(E_ALL); after <?php at the top. See if anything comes up then. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.