Jump to content
Larry Ullman's Book Forums

Frostbite

Members
  • Posts

    15
  • Joined

  • Last visited

Frostbite's Achievements

Newbie

Newbie (1/14)

0

Reputation

  1. Hi, Today I typed out the activation php code again. and what ever I did this time it seemed to work. Thank you for all your help.
  2. Okay so I just put print_r($_GET); at the top of my code and this is what I got back. Array ( [x] => alexp2510@hotmail.com [y] => 254e24e81bdec9b1d4b7baaac3dc00d6 ) Regards Alex
  3. Ok so I changed $trimmed['email'] to $_GET['x'] but that didn't work either, I still get a black screen with all my divs but no message if (isset($_GET['x'], $_GET['y']) && filter_var($_GET['x'],FILTER_VALIDATE_EMAIL) && (STRlen($_GET['y']) == 32 )) Maybe I laid it out wrong? Regards Alex
  4. I tired to change the %40 in the URL to @ but this did not work. it still just brings up a blank page with my main divs but no message saying it failed or succeed and does not redirect me to the index.php Regards Alex
  5. I hope this is what you meant: http://powerplaymc.co.uk/activate.php?x=eaxmple%40hotmail.com&y=83ffeabbc8e6701e16637e57075b2913 Regards Alex
  6. I believe so yes. Below is a copy of my database. CREATE TABLE IF NOT EXISTS users( user_id INT UNSIGNED NOT NULL AUTO_INCREMENT, user_name VARCHAR(20) NOT NULL, email VARCHAR(60) NOT NULL, pass CHAR(40) NOT NULL, reg_date DATETIME NOT NULL, user_level TINYINT(1) UNSIGNED NOT NULL default 0, active CHAR(32), PRIMARY KEY (user_id), UNIQUE (user_name), UNIQUE (email), INDEX login (user_name, pass) )ENGINE = INNODB; Regards Alex
  7. I may be wrong with is but if you look in the ch03 folder then go to in the includes folder there is a file named style.css I believe this is the correct file. Regards Alex
  8. Hello, I have been having trouble with this for quite some time I have tired to narrow it down the best I can. I able to complete the registration process, I went and check the sql database all fields have been filled. I think that the activation page cannot access the database to remove the active code. I tried to print or echo out the query value with echo "<p>Q: $q</p>" or print "<p>Q: $q</p>" all I see on the screen is "Q:" When I click the link from my email it doesn't seem to fail as it does not redirect me to index.php. I also do not get any error on my screen either. Any would help would be greatly appreciated. Regards Alex <div id="activate"> <?php /** * @author Alex Power * @copyright 2013 */ # Script 18.7 - activate.php require ('includes/config.inc.php'); $page_title='Activate Your Account'; if (isset($_GET['x'], $_GET['y']) && filter_var($trimmed['email'],FILTER_VALIDATE_EMAIL) && (STRlen($_GET['y']) == 32 )) { require (MYSQL); $q = "UPDATE users SET active=NULL WHERE (email='" . mysqli_real_escape_string($dbc, $_GET['x']) . "' AND active='" .mysqli_real_escape_sting($dbc, $_GET['y']) . "') LIMIT 1"; print "<p> Q: $q</p>"; $r = mysqli_query($dbc, $q) or trigger_error("Query:$q\n<br />)MySQL Error:" . mysqli_error($dbc)); if (mysqli_affected_rows($dbc)== 1 ) { echo "<h3>Your account is now active. You may now login.</h3>"; } else { echo '<p class="error">Your account could not be activated. Please re-check the link or contact the system administrator.</p>'; } mysqli_close($dbc); } else { //Redirect $url = BASE_URL . 'index.php'; ob_end_clean(); header("location:$url"); exit(); } // END of main IF-ELSE ?> </div>
  9. That seemed to fix it. I also cleared the users database and tried to register again and it worked. Thank you Larry and also Webrawa for all your help on my problem. Thanks again Alex
  10. I ran the echo's and all of the variable appeared un: Frostbite e: alexp2510@hotmail.com p: testpass An error has occurred in the script '/home/a2687587/public_html/register.php' on line : Query: INSERT INTO users (user_name, email, pass, active, reg_date) VALUES ('alexp2510@hotmail.com', 'Frostbite', SHA1('testpass'), '873ec23e8b761496dd2990ba20204075', NOW()) MYSQL Error:Duplicate entry 'alexp2510@hotmail.co' for key 'user_name' Date/Time: 8-26-13 15:08:53 #0 my_error_handler(1024, Query: INSERT INTO users (user_name, email, pass, active, reg_date) VALUES ('alexp2510@hotmail.com', 'Frostbite', SHA1('testpass'), '873ec23e8b761496dd2990ba20204075', NOW()) I then was given this error. I am unsure what it means duplicate entry Thanks Alex
  11. I managed to fix the problems with the SQL statement so thank you for your help on that. I am still just getting "please try again". I have tried to place the echo or print in 3-4 different places and no error appears echo $un; echo $p; echo $e; require('includes/config.inc.php'); $page_title = 'Register'; if ($_SERVER['REQUEST_METHOD'] == 'POST') { require (MYSQL); $trimmed = array_map('trim', $_POST); $un = $e = $p = false; require('includes/config.inc.php'); $page_title = 'Register'; if ($_SERVER['REQUEST_METHOD'] == 'POST') { require (MYSQL); $trimmed = array_map('trim', $_POST); $un = $e = $p = false; echo $un; echo $p; echo $e; if ($un && $e && $p) echo $un; echo $p; echo $e; { After I place the echo here I get an error on line 172: (Parse error: syntax error, unexpected T_ELSE in /home/a2687587/public_html/register.php on line 172) } else // Line 172 { echo '<p class="error">Please try again.</p>'; } mysqli_close($dbc); } I also placed echo also under all of the variables and it should the username and also the email but not the password. if (preg_match ('/^[A-z\'.-]{4,20}$/i',$trimmed['user_name'])) { $un = mysqli_real_escape_string ($dbc, $trimmed['user_name']); echo $un; // Variable 1 } else { echo '<p class="error">Please enter your username! </p>'; } if (filter_var($trimmed['email'], FILTER_VALIDATE_EMAIL)) { $e = mysqli_real_escape_string ($dbc, $trimmed['email']); echo $e; // Variable 2 } else { echo '<p class="error>Please enter a valid email address! </p>'; } if (preg_match ('/^\w{4-20}$/',$trimmed['password1'])) { if ($trimmed['password1'] == $trimmed['password2']) { $p = mysqli_real_escape_string ($dbc, $trimmed ['password1']); echo $p; // Variable 3 } else { echo '<p class="error">Your password did not match the confirmed password!</p>'; } } else { '<p class="error">Please enter a vaild password!</p>'; } Thanks Alex
  12. Sorry to be a pain but could you explain what you mean by print or refer to a chapter in your book. Also I tired to change the condition from false to true $un && $e && $p = TRUE; I was given an error: #0 my_error_handler(1024, Query: SELECT user_id From users WHERE user_name='Frostbite', email='example@thisaddress.com' Thanks Alex
  13. I removed the spaces and it fixed the "Enter username" but I am now getting "Please try again" Thanks Alex
  14. Hello, I am fairly new at php and mysql but finding the book very useful. I am having trouble with trying to register an account I fill out the registration form but when I click submit all I get is "Please enter your username" I am not getting any error appearing so I can not find out what the problem is. Here is my code I hope it is easy enough to read. I am also using a test server on 000webhost ("http://testwebserver.comli.com/register.php") I also have a localhost. <?php # register.php require('includes/config.inc.php'); $page_title = 'Register'; if ($_SERVER['REQUEST_METHOD'] == 'POST') { require (MYSQL); $trimmed = array_map('trim', $_POST); $un = $e = $p = FALSE; if (preg_match ('/^[A-z \' .-]{4,20} $/i', $trimmed['user_name'])) { $un = mysqli_real_escape_string ($dbc, $$trimmed['user_name']); } else { echo '<p class="error">Please enter your username! </p>'; } if (filter_var($trimmed['email'], FILTER_VALIDATE_EMAIL)) { $e = mysqli_real_escape_string ($dbc, $trimmed['email']); } else { echo '<p class="error>Please enter a valid email address! </p>'; } if (preg_match ('/^\w{4-20} $/', $trimmed['password1'])) { if ($trimmed['password1'] == $trimmed['password2']) { $p = mysqli_real_escape_string ($dbc, $trimmed ['password1']); } else { echo '<p class="error">Your password did not match the confirmed password!</p>'; } } else { '<p class="error">Please enter a vaild password!</p>'; } if ($un && $e && $p) { $q = "SELECT user_id From users WHERE user_name='$un', email='$e'"; $r = mysqli_query ($dbc,$q) or trigger_error("Query: $q\n<br />MYSQL Error:" . mysqli_error($dbc)); if (mysqli_num_rows($r) ==0) { $a = md5(uniqid(rand() , true)); $q = "INSERT INTO users (user_name, email, pass, active, reg_date) VALUES ('$e', '$un', SHA1('$p'), '$a', NOW())"; $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MYSQL Error:". mysqli_error($dbc)); if (mysqli_affected_rows($dbc) == 1) { $body = "Thank you for reistering at PowerPlay. To activate your account, please click on this link:\n\n"; $body .= BASE_URL . 'activate.php?x='.urencode($e) . "&y=$a"; mail($trimmed['email'], 'Registration Confirmation', $body, 'From alexp2510@hotmail.com'); echo '<h3>Thank you for registering! A confirmation email has been sent to your email address. Please click on the link in order to activate your account.</h3>'; exit(); } else { // if it did not run OK. echo '<p class="error">You could not be registered due to a system error. we apologize for any inconvenience.</p>'; } } else { echo '<p class="error">That email address or username is already in use. If you have forgotten your password use the link at the right to have your password sent to you.</p>'; } } else { echo '<p class="error">Please try again.</p>'; } mysqli_close($dbc); } ?> <h1>Register</h1> <form action="register.php" method="POST"> <fieldset> <p><b>Username:</b> <input type="text" name="user_name" size="20" maxlength="20" value="<?php if (isset($trimmed['user_name'])) echo $_POST['user_name'];?>" /> </p> <p><b>Email Address:</b> <input type="text" name="email" size="30" maxlength="60" value="<?php if (isset($trimmed['email'])) echo $trimmed ['email']; ?>" /> </p> <p><b>Password:</b> <input type="password" name="password1" size="20" maxlength="20" value="<?php if (isset($trimmed['password1'])) echo $trimmed ['password1']; ?>" /> <small> Use only letters, numbers, and the underscore. <p>Must be between 4 and 20 characters long.</p></small></p> <p><b>Confirm Password:</b> <input type="password" name="password2" size="20" maxlength="20" value="<?php if (isset($trimmed['password2'])) echo $trimmed['password2']; ?>" /> </p> </fieldset> <div align="center"> <input type="submit" name="submit" value="Register" /></div> </form> Any help would be great. Thanks Alex
×
×
  • Create New...