Garath531 Posted March 30, 2007 Share Posted March 30, 2007 <?php 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()); $SESSION['status'] = "Loggedin"; $SESSION['username'] = $username; echo "Welcome, ".$username."You are now logged in. <a href='?act=login'>Log in</a>"; }} function register_form() { echo "<center><img src='My Pictures/Waffle Banner.jpg'> <form action='?act=register' method='POST'> <b>Please register below</b> <table align='center' border='0'> <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>Confirm your password:</td> <td><input type='password' name='pass_conf'></td> </tr> <tr> <td> E-mail: </td> <td> <input type='text' name='email'> </td> </tr> <tr><td></td><td> <input type='submit' value='Register'></td></tr> </table> </form> </center>"; } function login() { header("Location: index.php");} $act = $_GET['act']; switch($act){ case register: register(); break; case login: login(); break; default: register_form(); } ?> That is my code. It goes through the checking of the data, but then doesn't do anything. Does anybody have any idea why? Php 5.2.1, Apache 2.0.59 Mysql 5.0. Safe mode OFF. I'm think it has to do with the if statements, but I can't figure out what. Link to comment https://forums.phpfreaks.com/topic/44972-nothing-is-happening-when-everything-checks-out-ok/ Share on other sites More sharing options...
micah1701 Posted March 30, 2007 Share Posted March 30, 2007 at the end of your function where you have: echo "Welcome, ".$username."You are now logged in. <a href='?act=login'>Log in</a>"; change to: $message = "Welcome, ".$username."You are now logged in. <a href='?act=login'>Log in</a>"; return $message; does that help? (i suck at writing functions so it might not solve your problem) Link to comment https://forums.phpfreaks.com/topic/44972-nothing-is-happening-when-everything-checks-out-ok/#findComment-218327 Share on other sites More sharing options...
Garath531 Posted March 30, 2007 Author Share Posted March 30, 2007 No it doesn't. I've checked my database and it doesn't put in the information either. Link to comment https://forums.phpfreaks.com/topic/44972-nothing-is-happening-when-everything-checks-out-ok/#findComment-218333 Share on other sites More sharing options...
gudmunson Posted March 30, 2007 Share Posted March 30, 2007 I think i see an issue, I had this problem when upgrading from php 4 to php5. in this code: //Check to see if username is in use already. $sql=mysql_query("SELECT username from users WHERE username = '$username'") or die(mysql_error ()); change the query to: mysql_query("SELECT username from users WHERE username = ' " . $username . " ' ") I had to change that in a bunch of pages and as soon as I did it, my pages started working again. Hope this helps. Link to comment https://forums.phpfreaks.com/topic/44972-nothing-is-happening-when-everything-checks-out-ok/#findComment-218342 Share on other sites More sharing options...
Garath531 Posted March 30, 2007 Author Share Posted March 30, 2007 Thanks for your help, but I already got that part to work. My problem is after that when it is supposed to register the user. I've checked my database and it doesn't enter anything. Link to comment https://forums.phpfreaks.com/topic/44972-nothing-is-happening-when-everything-checks-out-ok/#findComment-218357 Share on other sites More sharing options...
gudmunson Posted March 30, 2007 Share Posted March 30, 2007 Hmm, have you tried changing this: $query = "INsERT INTO users (username, password, email) values ('$username', '$new_pass', '$email')"; into this? $query = "INsERT INTO users (username, password, email) values ('" . $username . "', '" . $new_pass . "', '" . $email. "')"; It's possible that the reason it isn't inserting into your database is because it is giving an SQL syntax error. If you aren't getting one, I'm not sure what the issue is. The other thing to check is to make sure that username, password, and email are all valid fields in your table. Link to comment https://forums.phpfreaks.com/topic/44972-nothing-is-happening-when-everything-checks-out-ok/#findComment-218364 Share on other sites More sharing options...
Garath531 Posted March 30, 2007 Author Share Posted March 30, 2007 I tried it but it didn't work. Username, email, and pasword are all in my database. Link to comment https://forums.phpfreaks.com/topic/44972-nothing-is-happening-when-everything-checks-out-ok/#findComment-218365 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.