matthew798 Posted August 30, 2008 Share Posted August 30, 2008 This entire script is for managing user registration.... It is SUPPOSED to return the following when somebody successfully registers: "User registration successful! Your userid and password have been emailed to , the email address you just provided in your registration form. To log in, click here to return to the login page, and enter your new personal userid and password." instead, it displays nothing, and does not enter ANY of the info into the mySQL database... <?php // signup.php include 'common.php'; include 'db.php'; if (!isset($_POST['submitok'])): // Display the user signup form ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>New User Registration</title> </head> <body> <?php else: // Process signup submission dbConnect('sessions'); if ($_POST['username']=='' or $_POST['password']=='' or $_POST['email']=='') { error('One or more required fields were left blank.\\n'. 'Please fill them in and try again.'); } // Check for existing user with the new id $sql = "SELECT COUNT(*) FROM user WHERE userid = '$_POST[username]'"; $result = mysql_query($sql); if (!$result) { error('A database error occurred in processing your '. 'submission.\\nIf this error persists, please '. 'contact matthew.goulart@gmail.com.'); } if (@mysql_result($result,0,0)>0) { error('A user already exists with your chosen userid.\\n'. 'Please try another.'); } $sql = "INSERT INTO user SET username = '$_POST[username]', password = '$_POST[password], email = '$_POST[email]', country = '$_POST[country]', province = '$_POST[province]'"; if (!mysql_query($sql)) error('A database error occurred in processing your '. 'submission.\\nIf this error persists, please '. 'contact matthew.goulart@gmail.com.'); // Email the new password to the person. $message = "G'Day! Your personal account for the Project Web Site has been created! To log in, proceed to the following address: http://www.example.com/ Your personal login ID and password are as follows: userid: $_POST[username] password: $_POST[password] You aren't stuck with this password! Your can change it at any time after you have logged in. If you have any problems, feel free to contact me at <you@example.com>. -Your Name Your Site Webmaster "; mail($_POST['newemail'],"Your Password for Your Website", $message, "From:Your Name <you@example.com>"); ?> <p><strong>User registration successful!</strong></p> <p>Your userid and password have been emailed to <strong><?php $_POST[email] ?></strong>, the email address you just provided in your registration form. To log in, click <a href="index.php">here</a> to return to the login page, and enter your new personal userid and password.</p> <?php endif; ?> </body> </html> here are the two included files... common.php <?php // common.php function error($msg) { ?> <html> <head> <script language="JavaScript [10]"> <!-- alert("<?php $msg ?>"); history.back(); //--> </script> </head> <body> </body> </html> <?php exit; } ?> db.php <?php // db.php $dbhost = "localhost"; $dbuser = "****"; $dbpass = "****"; function dbConnect($db="") { global $dbhost, $dbuser, $dbpass; $dbcnx = @mysql_connect($dbhost, $dbuser, $dbpass) or die("The site database appears to be down."); if ($db!="" and !@mysql_select_db($db)) die("The site database is unavailable."); return $dbcnx; } ?> P.S. I starred out the user and pass... If anyone could tell me why it's not returning anything or writing anything to the databse... I know for a fact that the database info is correct and that the table does infact exist. Thanks in advance!!! Quote Link to comment https://forums.phpfreaks.com/topic/121942-trouble-with-user-registration/ Share on other sites More sharing options...
DeanWhitehouse Posted August 30, 2008 Share Posted August 30, 2008 Add some error reporting remove the @ from the connecting function and add error_reporting(E_ALL); to the top of the pages and add die statements to the mysql_querys. Quote Link to comment https://forums.phpfreaks.com/topic/121942-trouble-with-user-registration/#findComment-629350 Share on other sites More sharing options...
DarkWater Posted August 30, 2008 Share Posted August 30, 2008 Add these 4 lines to the top of your script: <?php ini_set('display_errors', 1); error_reporting(E_ALL); ?> Quote Link to comment https://forums.phpfreaks.com/topic/121942-trouble-with-user-registration/#findComment-629352 Share on other sites More sharing options...
Fadion Posted August 30, 2008 Share Posted August 30, 2008 Not sure if that is causing the problem, but this: $sql = "SELECT COUNT(*) FROM user WHERE userid = '$_POST[username]'"; should be: <?php $sql = "SELECT COUNT(*) FROM user WHERE userid = '{$_POST['username']}'"; //or $sql = "SELECT COUNT(*) FROM user WHERE userid = '" . $_POST['username'] . "'"; ?> And that issue is everywhere in the queries. Not mentioning that you must clean your input by escaping special characters with mysql_real_escape_string(). PS. I didnt know that an if() else could be written as if(): else: Quote Link to comment https://forums.phpfreaks.com/topic/121942-trouble-with-user-registration/#findComment-629354 Share on other sites More sharing options...
DarkWater Posted August 30, 2008 Share Posted August 30, 2008 You need endif; too, GuiltyGear. You can also use it for while, foreach, for, etc. Look up the syntax in the PHP manual. I think it's ugly though. Quote Link to comment https://forums.phpfreaks.com/topic/121942-trouble-with-user-registration/#findComment-629356 Share on other sites More sharing options...
kratsg Posted August 30, 2008 Share Posted August 30, 2008 Not sure if that is causing the problem, but this: $sql = "SELECT COUNT(*) FROM user WHERE userid = '$_POST[username]'"; should be: <?php $sql = "SELECT COUNT(*) FROM user WHERE userid = '{$_POST['username']}'"; //or $sql = "SELECT COUNT(*) FROM user WHERE userid = '" . $_POST['username'] . "'"; ?> And that issue is everywhere in the queries. Not mentioning that you must clean your input by escaping special characters with mysql_real_escape_string(). PS. I didnt know that an if() else could be written as if(): else: Never knew it either o_o It seems ugly.. I'd use semicolons just for switch/case/break statements. Quote Link to comment https://forums.phpfreaks.com/topic/121942-trouble-with-user-registration/#findComment-629358 Share on other sites More sharing options...
.josh Posted August 30, 2008 Share Posted August 30, 2008 first thing I personally see wrong is that you are using a colon instead of brackets with your if...else statement. Colons are used for executing just one expression but you have multiple expressions (multiple lines of code to be executed) so they need to be wrapped in brackets if (condition) { // code here } else { // code here } Quote Link to comment https://forums.phpfreaks.com/topic/121942-trouble-with-user-registration/#findComment-629359 Share on other sites More sharing options...
Fadion Posted August 30, 2008 Share Posted August 30, 2008 You need endif; too, GuiltyGear. You can also use it for while, foreach, for, etc. Look up the syntax in the PHP manual. I think it's ugly though. I see. Personally I'm pretty fine with curly braces, as that [if; else; endif;] thing reminds me of Visual Basic Quote Link to comment https://forums.phpfreaks.com/topic/121942-trouble-with-user-registration/#findComment-629364 Share on other sites More sharing options...
matthew798 Posted August 30, 2008 Author Share Posted August 30, 2008 well i have tried all of you suggestions to no avail... Except for the one about curly brackets instead of semi-colons... I couldn't find any in the script... (???) It would also be important to note that this script is entirely taken from http://www.sitepoint.com/print/users-php-sessions-mysql I changed it around a little bit to suit my needs but nothing major and i havn't changed the syntax of anything... here is my code so far, although still not working... ***NEWUS.PHP*** <?php ini_set('display_errors', 1); error_reporting(E_ALL); ?> <?php // signup.php include 'common.php'; include 'db.php'; if (!isset($_POST['submitok'])): // Display the user signup form ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>New User Registration</title> </head> <body> <?php else: // Process signup submission dbConnect('users'); if ($_POST['username']=='' or $_POST['password']=='' or $_POST['email']=='') { error('One or more required fields were left blank.\\n'. 'Please fill them in and try again.'); } // Check for existing user with the new id $sql = "SELECT COUNT(*) FROM users WHERE username = '{$_POST['username']}'"; $result = mysql_query($sql); if (!$result) { error('A database error occurred in processing your '. 'submission.\\nIf this error persists, please '. 'contact matthew.goulart@gmail.com.'); die("The site database is unavailable."); } if (@mysql_result($result,0,0)>0) { error('A user already exists with your chosen userid.\\n'. 'Please try another.'); die("The site database is unavailable."); } $sql = "INSERT INTO user SET username = '$_POST[username]', password = '$_POST[password], email = '$_POST[email]', country = '$_POST[country]', province = '$_POST[province]'"; die("The site database is unavailable."); if (!mysql_query($sql)) error('A database error occurred in processing your '. 'submission.\\nIf this error persists, please '. 'contact matthew.goulart@gmail.com.'); die("The site database is unavailable."); // Email the new password to the person. $message = "G'Day! Your personal account for the Project Web Site has been created! To log in, proceed to the following address: http://www.example.com/ Your personal login ID and password are as follows: userid: $_POST[username] password: $_POST[password] You aren't stuck with this password! Your can change it at any time after you have logged in. If you have any problems, feel free to contact me at <you@example.com>. -Your Name Your Site Webmaster "; mail($_POST['newemail'],"Your Password for Your Website", $message, "From:Your Name <you@example.com>"); ?> <p><strong>User registration successful!</strong></p> <p>Your userid and password have been emailed to <strong><?php $_POST[email] ?></strong>, the email address you just provided in your registration form. To log in, click <a href="index.php">here</a> to return to the login page, and enter your new personal userid and password.</p> <?php endif; ?> </body> </html> ***COMMON.PHP*** <?php ini_set('display_errors', 1); error_reporting(E_ALL); ?> <?php // common.php function error($msg) { ?> <html> <head> <script language="JavaScript [10]"> <!-- alert("<?php $msg ?>"); history.back(); //--> </script> </head> <body> </body> </html> <?php exit; } ?> ***DB.PHP*** <?php ini_set('display_errors', 1); error_reporting(E_ALL); ?> <?php // db.php $dbhost = "localhost"; $dbuser = "admin"; $dbpass = "1admin"; function dbConnect($db="users") { global $dbhost, $dbuser, $dbpass; $dbcnx = mysql_connect($dbhost, $dbuser, $dbpass) or die("The site database appears to be down."); if ($db!="users" and !mysql_select_db($db)) die("The site database is unavailable."); return $dbcnx; } ?> P.S. i spearated the three files with stars and big letters so my post wouldnt be so cluttered... oh yeah, and those error reporting lines i added aren't doing anything... (also important to note, i started PHP yesterday. I know a good bit of C++ and heard it was similar so i decided to give it a whirl. Also, i'm learning it so i can offer it as a course in my local business i run !!! ) Quote Link to comment https://forums.phpfreaks.com/topic/121942-trouble-with-user-registration/#findComment-629369 Share on other sites More sharing options...
DarkWater Posted August 30, 2008 Share Posted August 30, 2008 It's nothing like C++....not really, at least. Quote Link to comment https://forums.phpfreaks.com/topic/121942-trouble-with-user-registration/#findComment-629373 Share on other sites More sharing options...
matthew798 Posted August 30, 2008 Author Share Posted August 30, 2008 It's nothing like C++....not really, at least. If, else, for loop... Sounds like C++ to me... Quote Link to comment https://forums.phpfreaks.com/topic/121942-trouble-with-user-registration/#findComment-629375 Share on other sites More sharing options...
DarkWater Posted August 30, 2008 Share Posted August 30, 2008 It's nothing like C++....not really, at least. If, else, for loop... Sounds like C++ to me... I can't even think of a high level language that doesn't have similar or comparable constructs. Quote Link to comment https://forums.phpfreaks.com/topic/121942-trouble-with-user-registration/#findComment-629381 Share on other sites More sharing options...
matthew798 Posted August 30, 2008 Author Share Posted August 30, 2008 Ah, well thats good to know. What would be BETTER to know is the answer to my question! Quote Link to comment https://forums.phpfreaks.com/topic/121942-trouble-with-user-registration/#findComment-629385 Share on other sites More sharing options...
DeanWhitehouse Posted August 30, 2008 Share Posted August 30, 2008 Sometimes threads go off topic some times. Are there no errors on the page? Quote Link to comment https://forums.phpfreaks.com/topic/121942-trouble-with-user-registration/#findComment-629387 Share on other sites More sharing options...
matthew798 Posted August 30, 2008 Author Share Posted August 30, 2008 well, it's all in an I-Frame... I hope that doesn't matter... And no, there is no output whatsoever... Quote Link to comment https://forums.phpfreaks.com/topic/121942-trouble-with-user-registration/#findComment-629390 Share on other sites More sharing options...
.josh Posted August 30, 2008 Share Posted August 30, 2008 if (!isset($_POST['submitok'])): // Display the user signup form ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>New User Registration</title> </head> <body> <?php else: // Process signup submission dbConnect('users'); . . . Quote Link to comment https://forums.phpfreaks.com/topic/121942-trouble-with-user-registration/#findComment-629513 Share on other sites More sharing options...
DeanWhitehouse Posted August 30, 2008 Share Posted August 30, 2008 Crayon Violent are u not missing an endif? Quote Link to comment https://forums.phpfreaks.com/topic/121942-trouble-with-user-registration/#findComment-629880 Share on other sites More sharing options...
.josh Posted August 30, 2008 Share Posted August 30, 2008 There's no such thing as endif in php. The brackets are what signify the beginning and end of the code blocks to be executed. In my first post in this thread I pointed out that he is using a colon instead of brackets. Well colons can be used if you are only going to be executing 1 line of code, but he's not, so he needs to wrap the code blocks in brackets (see my first post). He said he didn't see any colons, so I pointed them out. I don't know whether or not this will completely fix his problem but I do know that that's at least one thing wrong with his code. I didn't look any further into it than that. Quote Link to comment https://forums.phpfreaks.com/topic/121942-trouble-with-user-registration/#findComment-629951 Share on other sites More sharing options...
DeanWhitehouse Posted August 30, 2008 Share Posted August 30, 2008 Ahh i thought you where posting the code as an anwser, thats why i asked lozl. Quote Link to comment https://forums.phpfreaks.com/topic/121942-trouble-with-user-registration/#findComment-629955 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.