evanct Posted January 16, 2009 Share Posted January 16, 2009 this is just a simple little script, but I've been wrestling with it for an hour and can't figure out what's wrong with it. All I get is a blank page, except for what's included in header.php and footer.php. no error messages or anything. The data is also not being entered into the mysql table. here's the script: <?php session_start(); include('mysqllogin.php'); include('header.php'); require('functions.php'); $email=$_POST['email']; $firstname=$_POST['firstname']; $lastname=$_POST['lastname']; $username=$_POST['username']; $pass=$_POST['pass']; $pass2=$_POST['pass2']; $query="INSERT INTO users VALUES (NULL, '$firstname', '$lastname', '$username', '$pass', '$email')"; if (empty($firstname) || empty($lastname) || empty($username) || empty($email) || empty($pass) || empty($pass2)) { $_SESSION['error']="One or more fields was left blank."; } else { if (checkEmail($email)==FALSE) { $_SESSION['error']="Invalid email."; } else { $result=mysql_query($query) or die('Could not query the database.'); echo '<div class="wrapper">'; echo 'Thank you for registering. You may now log in.'; echo '</div>'; } } echo $_SESSION['error']; include('footer.php'); ?> I echoed $_POST['firstname'] and $firstname and they both returned the correct values, so no problem there. is there something else i'm missing? Quote Link to comment Share on other sites More sharing options...
corbin Posted January 16, 2009 Share Posted January 16, 2009 Are you sure footer.php is being included? Perhaps something in functions.php is killing the script? If you throw an echo statement in there right before footer.php, does it echo? Quote Link to comment Share on other sites More sharing options...
evanct Posted January 16, 2009 Author Share Posted January 16, 2009 Are you sure footer.php is being included? Perhaps something in functions.php is killing the script? If you throw an echo statement in there right before footer.php, does it echo? footer.php is being included, to be sure i put an echo just before the include, and in footer.php itself, and they both worked. functions.php is, as the name would imply, just a bunch of functions, no executed code that would interfere. but here's the function checkEmail if it matters: function checkEmail($email) { $regexp = "^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$"; if (!eregi($regexp,$email)) { return FALSE; } list($user,$domain)=split('@',$email); if(function_exists("getmxrr") && getmxrr($domain,$MXHost)) { return TRUE; } elseif (@fsockopen($domain,25,$errno,$errstr,30)) { return TRUE; } else { return FALSE; } } Quote Link to comment Share on other sites More sharing options...
corbin Posted January 16, 2009 Share Posted January 16, 2009 If you view the source is anything in the middle? Quote Link to comment Share on other sites More sharing options...
evanct Posted January 16, 2009 Author Share Posted January 16, 2009 If you view the source is anything in the middle? No, and the footer.php content isn't there either! just the header.php content. Quote Link to comment Share on other sites More sharing options...
revraz Posted January 16, 2009 Share Posted January 16, 2009 Turn on display errors and error reporting. Echo your query. Post your FORM. Use mysql_error() after your query to check for errors. Quote Link to comment Share on other sites More sharing options...
evanct Posted January 16, 2009 Author Share Posted January 16, 2009 Turn on display errors and error reporting. Echo your query. Post your FORM. Use mysql_error() after your query to check for errors. Everything was A-ok when i echoed the query. display errors and error reporting are both on already. I even set it to display notices just to be safe, and still nothing. mysql_error() returned... nothing. and the form: <?php include('header.php'); require('functions.php'); echo '<div class="wrapper" style="min-height:200px;"> <form action="registered.php" method="POST"> First name: <input type="text" name="firstname" /> <br/> Last name: <input type="text" name="lastname" /> Username: <input type="text" name="username" /> Password: <input type="password" name="pass" /> Confirm password: <input type="password" name="pass2" /> Email: <input type="text" name="email" /> <br/> <input type="submit" name="submit" /> </form> </div>'; include('footer.php'); ?> Quote Link to comment Share on other sites More sharing options...
phparray Posted January 16, 2009 Share Posted January 16, 2009 You are mixing include() and require() while these functions are similar but differ specifically in the way they handle failure. Include will not kill the script on a file not found. Change each use of include to require and I think you will find mysqllogin.php or header.php is not found. Quote Link to comment Share on other sites More sharing options...
evanct Posted January 16, 2009 Author Share Posted January 16, 2009 You are mixing include() and require() while these functions are similar but differ specifically in the way they handle failure. Include will not kill the script on a file not found. Change each use of include to require and I think you will find mysqllogin.php or header.php is not found. Nope. The script's still goin' strong. Quote Link to comment Share on other sites More sharing options...
phparray Posted January 16, 2009 Share Posted January 16, 2009 I've taken all the code you posted and put it up on a test server where it is running fine. I stripped away the mysql part and commented out all the includes with the exception of the functions.php include. This proves the conditional logic works correctly including the email validation script. I usually put the mysql_error() in the die() function. But since you are not getting the Could not query the database message either that's not going to help. Are you certain your mysqllogin.php file is connecting to the db and properly selecting the database? Are those functions also validating before processing? Quote Link to comment Share on other sites More sharing options...
evanct Posted January 16, 2009 Author Share Posted January 16, 2009 I've taken all the code you posted and put it up on a test server where it is running fine. I stripped away the mysql part and commented out all the includes with the exception of the functions.php include. This proves the conditional logic works correctly including the email validation script. I usually put the mysql_error() in the die() function. But since you are not getting the Could not query the database message either that's not going to help. Are you certain your mysqllogin.php file is connecting to the db and properly selecting the database? Are those functions also validating before processing? mysqllogin.php is fine, i've been using it among several scripts for the past... long time. i don't know what you mean by validating the functions, but i've also been using this same functions.php script for a while, and there's never been a problem like this. if you think it's necessary, though, i can post the entire functions.php. I did a quick select and echo from the table, which worked, so it's obviously connecting properly. Quote Link to comment Share on other sites More sharing options...
phparray Posted January 16, 2009 Share Posted January 16, 2009 You stated the data is not getting inserted and I tested the conditional statements with good results after removing the MySql query. I have to conclude the problem is with MySql. It may not be the query but something about MySql itself. Verify the number of values in the insert matches the number of columns in your table. Verify the first column can handle a NULL as I see that's what your passing. If the column is set to NOT NULL this might be a problem so you would change the NULL to just two single quotes like this '' within VALUES(). You could also change your query to include the list of columns you are inserting into. The new query would look like this eliminating the need for a NULL to be passed at all: INSERT INTO users (columnName,columnName,columnName,...) VALUES('value','value','value','...'); If that doesn't work run show create table users on the MySql db and I'll create the table on a test environment and see it I can figure it out. Quote Link to comment Share on other sites More sharing options...
evanct Posted January 19, 2009 Author Share Posted January 19, 2009 You stated the data is not getting inserted and I tested the conditional statements with good results after removing the MySql query. I have to conclude the problem is with MySql. It may not be the query but something about MySql itself. Verify the number of values in the insert matches the number of columns in your table. Verify the first column can handle a NULL as I see that's what your passing. If the column is set to NOT NULL this might be a problem so you would change the NULL to just two single quotes like this '' within VALUES(). You could also change your query to include the list of columns you are inserting into. The new query would look like this eliminating the need for a NULL to be passed at all: INSERT INTO users (columnName,columnName,columnName,...) VALUES('value','value','value','...'); If that doesn't work run show create table users on the MySql db and I'll create the table on a test environment and see it I can figure it out. Tried all your suggestions, then i created a whole new table, I even reinstalled mysql... and I still get a blank page. I just don't see what the problem could be. here's the table creation: CREATE TABLE `stuff`.`users` (`user_id` INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY, `firstname` VARCHAR(150) NOT NULL, `lastname` VARCHAR(150) NOT NULL, `username` VARCHAR(20) NOT NULL, `pass` VARCHAR(160) NOT NULL, `email` VARCHAR(70) NOT NULL) ENGINE = InnoDB Anyone else want to take a whack at this? Quote Link to comment Share on other sites More sharing options...
phparray Posted January 19, 2009 Share Posted January 19, 2009 Here is a working example without including functions, header, footer. I removed them to focus on the mysql portion. This is 99% your code. I changed very little. This was successfully tested using XAMPP 1.6.8 for Windows (php 5.2.6 mysql 5.0.67) index.php <?php echo '<div class="wrapper" style="min-height:200px;"> <form action="action.php" method="POST"> First name: <input type="text" name="firstname" /> <br/> Last name: <input type="text" name="lastname" /> Username: <input type="text" name="username" /> Password: <input type="password" name="pass" /> Confirm password: <input type="password" name="pass2" /> Email: <input type="text" name="email" /> <br/> <input type="submit" name="submit" /> </form> </div>'; ?> action.php <?php session_start(); include('mysqllogin.php'); $email=$_POST['email']; $firstname=$_POST['firstname']; $lastname=$_POST['lastname']; $username=$_POST['username']; $pass=$_POST['pass']; $pass2=$_POST['pass2']; $query="INSERT INTO users VALUES (NULL, '$firstname', '$lastname', '$username', '$pass', '$email')"; if (empty($firstname) || empty($lastname) || empty($username) || empty($email) || empty($pass) || empty($pass2)) { $_SESSION['error']="One or more fields was left blank."; } else { $result=mysql_query($query) or die('Could not query the database.'); echo '<div class="wrapper">'; echo 'Thank you for registering. You may now log in.'; echo '</div>'; unset($_SESSION['error']); } echo (isset($_SESSION['error'])) ? $_SESSION['error'] : ''; mysql_close(); ?> mysqllogin.php <?php #replace *********** with connection details define('HOST',"***********"); define('DB',"stuff"); define('USER',"***********"); define('PASS',"***********"); @mysql_pconnect(HOST,USER,PASS) OR die(mysql_error()); mysql_select_db(DB); ?> If you use this and put things back in one at a time I'm sure you'll get it. But of course if anyone else has a suggestions please post. Quote Link to comment Share on other sites More sharing options...
evanct Posted January 19, 2009 Author Share Posted January 19, 2009 Finally i'm getting somewhere. if i remove this part: if (checkEmail($email)==FALSE) { echo "Invalid email."; } else { everything works. so I guess there's something wrong with function checkEmail. I already posted it a few posts up, if anyone wants to look at it. Quote Link to comment Share on other sites More sharing options...
revraz Posted January 19, 2009 Share Posted January 19, 2009 The second part of that function could be failing if(function_exists("getmxrr") && getmxrr($domain,$MXHost)) { return TRUE; } elseif (@fsockopen($domain,25,$errno,$errstr,30)) { return TRUE; } else { return FALSE; } Quote Link to comment Share on other sites More sharing options...
evanct Posted January 19, 2009 Author Share Posted January 19, 2009 Okay I tried all of that, phparray, but I still get the same results: it only works if I don't include the checkEmail() call. something about that kills the script. Quote Link to comment Share on other sites More sharing options...
evanct Posted January 19, 2009 Author Share Posted January 19, 2009 I just replaced the entire checkEmail function with this: function checkEmail($email) { if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { return false; } $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg("^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%& ↪'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { return false; } } if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])| ↪([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } } return true; } everything's fine now. thanks for your help everyone. 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.