jcl43 Posted November 19, 2008 Share Posted November 19, 2008 Hi all, I am working on a site that requires registration, and login to access certain content. I am having trouble debugging the code as no errors pop up when i hit register, and nothing happens on the backend. The php code that I have so far is here: <?php session_start(); include ('dbc.php'); if ($_POST['submit'] == 'register') { if (strlen($_POST['email']) < 5) { die ("Incorrect email. Please enter valid email address.."); } if (strcmp($_POST['pword1'],$_POST['pword2']) || empty($_POST['pword1']) ) { //die ("Password does not match"); die("ERROR: Password does not match or is empty.."); } if (strcmp(md5($_POST['user_code']),$_SESSION['ckey'])) { die("Invalid code entered. Please enter the correct code as shown in the Image"); } $rs_duplicates = mysql_query("select userId from CUser where email='$_POST[email]'"); $duplicates = mysql_num_rows($rs_duplicates); if ($duplicates > 0) { //die ("ERROR: User account already exists."); header("Location: register.php?msg=ERROR: User account already exists.."); exit(); } $username = $_Post['userId']; $md5pass = md5($_POST['pass2']); $fname = $_Post['fname']; $lname = $_Post['lname']; $email= $_Post['email']; $activcode = rand(1000,9999); $joined = now(); $activated = 1; $school = $_Post['CSU']; $as = $_Post['areaofstudy']; $emph = $_Post['emph']; $server = $_SERVER['HTTP_HOST']; $host = ereg_replace('www.','',$server); $command = "INSERT INTO CUser". "(userId, pword2, fname, lname, email,activation_code,". "joined, user_activated, schoolId, asCode, emphcode)". "VALUES". "('$username', '$md5pass', '$fname', '$lname', '$email', '$activcode', ". "'$joined', '$activated', '$school', 'as', 'emph')"; mysql_query($command) or die(mysql_error()); $message = "Thank you for registering an account with $server. Here are the login details...\n\n User Email: $_POST[email] \n Password: $_POST[pass2] \n Activation Code: $activ_code \n ____________________________________________ *** ACTIVATION LINK ***** \n Activation Link: http://$server/activate.php?usr=$_POST[email]&code=$activ_code \n\n _____________________________________________ Thank you. This is an automated response. PLEASE DO NOT REPLY. "; mail($_POST['email'] , "Login Activation", $message, "From: \"Auto-Response\" <notifications@$host>\r\n" . "X-Mailer: PHP/" . phpversion()); unset($_SESSION['ckey']); echo("Registration Successful! An activation code has been sent to your email address with an activation link..."); exit; } ?> The site can be found at www.humboldt.edu/~cis450rb the registration button is the only live link and takes you to the register.php which is the code posted above. If anybody can help out I would greatly appreciate it! Thanks in advance for your time Quote Link to comment Share on other sites More sharing options...
revraz Posted November 19, 2008 Share Posted November 19, 2008 Echo $command and post the results. Quote Link to comment Share on other sites More sharing options...
jcl43 Posted November 20, 2008 Author Share Posted November 20, 2008 Hi thanks for the help, I am unable to echo anything. Even if i take out all html and code except the $_Post form action and echo. How would you go about doing that? Sorry to sound so naive...any help is appreciated thanks Quote Link to comment Share on other sites More sharing options...
revraz Posted November 20, 2008 Share Posted November 20, 2008 Post your form code. Quote Link to comment Share on other sites More sharing options...
jcl43 Posted November 20, 2008 Author Share Posted November 20, 2008 Thank you, here is the form code: <form name="register" method="post" action="register.php"> <p> Choose a user name: <br> <input name="userId" type="text" id="userId" value=""> </p> <br> <p> Choose a password and enter it twice: <br> Passwords must be at least 6 characters and contain only alphanumerics <br><br> <input name="pword1" type="password" id="pword1" value=""> <input name="pword2" type="password" id="pword2" value=""> </p> <br> <p> First Name: <br> <input name="fname" type="text" id="fname" value=""> </p> <br> <p> Last Name: <br> <input name="lname" type="text" id="lname" value=""> </p> <br> <p> Enter a valid email address:<br> <input name="email" type="text" id="email" value=""> <br><br> Note: You will be sent an activation link at the<br> email address you provide. </p><br><br> <h2><a href="#">Tell us about yourself</a></h2><br> <p> What school do you attend? </p> <br> California State University: <select name ="CSU"> <option value ="">Choose a school</option> <option value ="bakersfield">Bakersfield</option> <option value ="channelislands">Channel Islands</option> <option value ="chico">Chico</option> <option value ="dominguezhills">Dominguez Hills</option> <option value ="eastbay">East Bay</option> <option value ="fresno">Fresno</option> <option value ="fullerton">Fullerton</option> <option value ="humboldt">Humboldt</option> <option value ="longbeach">Long Beach</option> <option value ="csulosangeles">CSU Los Angeles</option> <option value ="maritime">Maritime Academy</option> <option value ="montereybay">Monterey Bay</option> <option value ="northridge">Northridge</option> <option value ="pamona">Pamona</option> <option value ="sacramento">Sacramento</option> <option value ="sanbernadino">San Bernadino</option> <option value ="csusandiego">CSU San Diego</option> <option value ="csusanfrancisco">CSU San Francisco</option> <option value ="sanjose">San Jose</option> <option value ="sanluisobispo">San Luis Obispo</option> <option value ="sanmarcos">San Marcos</option> <option value ="sonoma">Sonoma</option> <option value ="stanislaus">Stanislaus</option> </select> <br><br><br><center>Or</center><br><br> University of California: <select name="UC"> <option value ="">Choose a school</option> <option value ="berkely">Berkely</option> <option value ="davis">Davis</option> <option value ="irvine">Irvine</option> <option value ="uclosangeles">Los Angeles</option> <option value ="merced">Merced</option> <option value ="riverside">Riverside</option> <option value ="ucsandiego">San Diego</option> <option value ="ucsanfrancisco">San Francisco</option> <option value ="santabarbara">Santa Barabara</option> <option value ="santacruz">Santa Cruz</option> </select> <br><br><br> <p> Please tell us your area of study and emphasis <br><br> This will help us bring you the most relevant infomation in order to provide the best access to all research opportunities. <br><br> </p> Note: We are currently limited to students enrolled in the STEM fields of research. <br><br> <select name="areaofstudy"> <option value ="">Choose an area of study</option> <option value ="compsci">Computer Science</option> <option value ="math">Mathematics</option> <option value ="physicalscience">Physical Sciences</option> <option value ="socialsciane">Social/Behavioral Sciences</option> <option value ="lifescience">Life Sciences</option> <option value ="geosci">Geo Sciences</option> <option value ="engineering">Engineering</option> <option value ="genetics">Genetics</option> </select> <br><br> Emphasis: <br> <input name="emph" type="text" id="emph" value=""> </p> <br><br> Please enter the numeric code below into the text box <br><br> This is help protect against automated spam registration <br><br> <input name="user_code" type="text" size="10"> <img src="pngimg.php" align="middle"> <br><br> <input name="register" type="submit" class="login" value="Register"> </form> It is on register.php along with the code I previously posted. It comes after the php code. Is that normal practice? Thanks again for your time Quote Link to comment Share on other sites More sharing options...
jcl43 Posted November 24, 2008 Author Share Posted November 24, 2008 Ok, so I have made some progress and was hoping someone could help out with my new issues. I changed the setup a bit, instead of the form action calling register.php it calls $_SERVER [php_SELF]. This works, the system sends an email when registering, but I get a mysql error "Duplicate entry '0' for key 1" on the next page. The entries are not being added to db, yet it also says successfully registered, and I get an email with the correct activation link etc. I decided to echo $command like suggested before and this is what it output: INSERT INTO CUser(userId, pword2, fname, lname, email,activation_code,joined, user_activated, schoolId, asCode, emphcode)VALUES('', 'd41d8cd98f00b204e9800998ecf8427e', '', '', '', '1713', now(), '1', '', 'as', 'emph') It doesnt seem as if the query is correct. If anyone could help out I would greatly appreciate it! Quote Link to comment Share on other sites More sharing options...
revraz Posted November 24, 2008 Share Posted November 24, 2008 Remove userId and ' ' from your field and value. Your ID field should be set to auto-increment, so you don't need to have these in your INSERT statement. Quote Link to comment Share on other sites More sharing options...
jcl43 Posted November 25, 2008 Author Share Posted November 25, 2008 Ok, I removed userId and made it auto increment. I am still getting syntax error though. This is what the user table looks like: +-----------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------------+-------------+------+-----+---------+----------------+ | userId | int(11) | | PRI | NULL | auto_increment | | username | varchar(20) | YES | MUL | NULL | | | pword1 | varchar(32) | YES | | NULL | | | pword2 | varchar(32) | YES | | NULL | | | fname | varchar(20) | YES | | NULL | | | lname | varchar(20) | YES | | NULL | | | email | varchar(20) | YES | | NULL | | | activation_code | varchar(50) | YES | | NULL | | | joined | date | YES | | NULL | | | user_activated | int(1) | YES | | NULL | | | schoolid | int(11) | YES | | NULL | | | ascode | int(11) | YES | | NULL | | | emphcode | int(11) | YES | | NULL | | | notifId | int(11) | YES | | NULL | | | externCode | int(1) | YES | | NULL | | +-----------------+-------------+------+-----+---------+----------------+ 15 rows in set (0.00 sec) Here is the error I am getting now: You have an error in your SQL syntax near ' d41d8cd98f00b204e9800998ecf8427e, , , , 6374, now(), 1, , , )' at line 1 This is what is output by echoing $command: INSERT INTO CUser(username, pword2, fname, lname, email, activation_code,joined, user_activated, schoolId, asCode, emphcode)VALUES(, d41d8cd98f00b204e9800998ecf8427e, , , , 6374, now(), 1, , , ) I am wondering why the values being inserted are blank, let me know if you can think of what I am doing wrong. I appreciate it! Thanks Quote Link to comment Share on other sites More sharing options...
revraz Posted November 25, 2008 Share Posted November 25, 2008 Remove the first comma after Values 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.