phpnoobie9 Posted January 14, 2008 Share Posted January 14, 2008 I was looking over this tutorial and can't seem to get it to work. http://www.dot-silver.co.uk/tutorials/view/14/Simple+Member+System/ I'm not able to add the username and password to the database. I did every step and still can't get it to work. <?php require "db.php"; if(!$_POST['register']){ print'<form method="post" action="'.$_SERVER['PHP_SELF'].'"> <label>Username</label><br/><input name="username"/><br/> <label>Password</label><br/><input name="password" type="password"/><br/> <input type="submit" name="register" value="register"/> </form>'; }else{ $lock = 'true'; if($lock == 'true') { print 'Copy and pasting gets you nowhere in life.'; die; }else{ $name = mysql_real_escape_string($_POST['username']); $pw = sha1($_POST['password']); mysql_query("INSERT INTO members (id, username, password) VALUES (NULL, '$user', '$pw')") or die('For some reason, we could not process your registration.'); print'Registration Successful. Head over to <a href="login.php">the login page</a>.'; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/85883-need-help-with-this-registration/ Share on other sites More sharing options...
pocobueno1388 Posted January 14, 2008 Share Posted January 14, 2008 Tell us what's not working about it. Quote Link to comment https://forums.phpfreaks.com/topic/85883-need-help-with-this-registration/#findComment-438481 Share on other sites More sharing options...
phpnoobie9 Posted January 14, 2008 Author Share Posted January 14, 2008 When I try registering it does not add the username and password to the database. It prints out 'Copy and pasting gets you nowhere in life.' because it's not registering. Quote Link to comment https://forums.phpfreaks.com/topic/85883-need-help-with-this-registration/#findComment-438482 Share on other sites More sharing options...
marcus Posted January 14, 2008 Share Posted January 14, 2008 <?php if(!$_POST['submit']){ // form }else { $user = mysql_real_escape_string($_POST['username']); $pass = mysql_real_escape_string($_POST['password']); $errors = array(); if(!$user){ $errors[] = "You did not supply a username"; }else { if(!in_array(strlen($user),range('3','32'))){ $errors[] = "Username must be between 3 and 32 characters"; } if(!ctype_alnum($user)){ $errors[] = "Username can only contain alphanumerical characters"; } $sql = "SELECT * FROM `users` WHERE `username`='".$user."'"; $res = mysql_query($sql) or die(mysql_error()); if(mysql_num_rows($res) == 0){ $errors[] = "The username already exists in the database"; } } if(!$pass){ $errors[] = "You did not supply a password"; }else { if(strlen($pass) < 6){ $errors[] = "Your password must be greater than or equal to 6"; } } if(count($errors) > 0){ echo "The following errors occurred:<br>\n"; foreach($errors AS $error){ echo $error . "<br>\n"; } }else { $sql2 = "INSERT INTO `users` (`username`,`password`) VALUES('".$user."','".sha1($pass)."')"; $res2 = mysql_query($sql2) or die(mysql_error()); echo "You have successfully registered as ".$user."!\n"; } } ?> give that a go. Quote Link to comment https://forums.phpfreaks.com/topic/85883-need-help-with-this-registration/#findComment-438483 Share on other sites More sharing options...
peranha Posted January 14, 2008 Share Posted January 14, 2008 Here is the line you missed on the tutorial as well Oh, and if you spot an error in the code, hit me up on the forums with a personal message. Oh, and set $lock from 'true' to 'false'. Quote Link to comment https://forums.phpfreaks.com/topic/85883-need-help-with-this-registration/#findComment-438485 Share on other sites More sharing options...
revraz Posted January 14, 2008 Share Posted January 14, 2008 You have this if(!$_POST['register']){ and then a else statement that sets $lock to true and then the next line compares $lock to true, so of course it will echo your Copy and Paste line. Why is that even there? Either they are clicking Register or they are not. You dont need two else statements like that and I dont see why any tutorial would do that unless you missed something. Quote Link to comment https://forums.phpfreaks.com/topic/85883-need-help-with-this-registration/#findComment-438486 Share on other sites More sharing options...
peranha Posted January 14, 2008 Share Posted January 14, 2008 It is in there so they dont copy and paste, they read the actual tutorial and are trying to learn PHP, not just copying off of everybody else. Quote Link to comment https://forums.phpfreaks.com/topic/85883-need-help-with-this-registration/#findComment-438488 Share on other sites More sharing options...
revraz Posted January 14, 2008 Share Posted January 14, 2008 Doesn't make sense. So it's say YOU shouldn't Copy and Paste their code? It is in there so they dont copy and paste, they read the actual tutorial and are trying to learn PHP, not just copying off of everybody else. Quote Link to comment https://forums.phpfreaks.com/topic/85883-need-help-with-this-registration/#findComment-438492 Share on other sites More sharing options...
marcus Posted January 14, 2008 Share Posted January 14, 2008 Try using my example. That tutorial is horrible and shouldn't be used. Quote Link to comment https://forums.phpfreaks.com/topic/85883-need-help-with-this-registration/#findComment-438494 Share on other sites More sharing options...
revraz Posted January 14, 2008 Share Posted January 14, 2008 I don't know, now that I think about it, it's pretty funny. He's copy and pasting code, then he realizes that section of code is in there to prevent copy and pasting the code, then he asks why it appears. Quote Link to comment https://forums.phpfreaks.com/topic/85883-need-help-with-this-registration/#findComment-438495 Share on other sites More sharing options...
peranha Posted January 14, 2008 Share Posted January 14, 2008 The writer put it in there so you run into problems when you just copy and paste code to use it. Quote Link to comment https://forums.phpfreaks.com/topic/85883-need-help-with-this-registration/#findComment-438500 Share on other sites More sharing options...
marcus Posted January 14, 2008 Share Posted January 14, 2008 Try using my example. That tutorial is horrible and shouldn't be used. Quote Link to comment https://forums.phpfreaks.com/topic/85883-need-help-with-this-registration/#findComment-438502 Share on other sites More sharing options...
peranha Posted January 14, 2008 Share Posted January 14, 2008 Try using my example. That tutorial is horrible and shouldn't be used. Nice, you can listen to a 26 minute tutorial, or change 1 word in you current file. I would choose 1 word. Quote Link to comment https://forums.phpfreaks.com/topic/85883-need-help-with-this-registration/#findComment-438504 Share on other sites More sharing options...
marcus Posted January 14, 2008 Share Posted January 14, 2008 Maybe if he actually WANTS to learn the fricekn thing, he'll take the time and watch it. But copy and pasting won't get him anywhere. Quote Link to comment https://forums.phpfreaks.com/topic/85883-need-help-with-this-registration/#findComment-438505 Share on other sites More sharing options...
phpnoobie9 Posted January 14, 2008 Author Share Posted January 14, 2008 The author said nothing about the $lock variable in the tutorial. The only thing I missed was the last line where he said change it to false. I was wondering why that else statement was there. The password is registering correctly, but the username is blank when I look at the database. Try using my example. That tutorial is horrible and shouldn't be used. Nice, you can listen to a 26 minute tutorial, or change 1 word in you current file. I would choose 1 word. Your video is blurry. Quote Link to comment https://forums.phpfreaks.com/topic/85883-need-help-with-this-registration/#findComment-438507 Share on other sites More sharing options...
peranha Posted January 14, 2008 Share Posted January 14, 2008 If he wanted to learn he WOULD HAVE READ IN THE TUTORIAL the first time. But you point is good. Quote Link to comment https://forums.phpfreaks.com/topic/85883-need-help-with-this-registration/#findComment-438509 Share on other sites More sharing options...
marcus Posted January 14, 2008 Share Posted January 14, 2008 You can obviously tell he only copied and pasted it, I'm sure he'd've read it if he really wanted to. Quote Link to comment https://forums.phpfreaks.com/topic/85883-need-help-with-this-registration/#findComment-438510 Share on other sites More sharing options...
phpnoobie9 Posted January 14, 2008 Author Share Posted January 14, 2008 You can obviously tell he only copied and pasted it, I'm sure he'd've read it if he really wanted to. Yeah I copied it. I understand it somewhat. I'm not even using it on any websites. I'm just using it on localhost with wampserver trying to learn it. Quote Link to comment https://forums.phpfreaks.com/topic/85883-need-help-with-this-registration/#findComment-438513 Share on other sites More sharing options...
peranha Posted January 14, 2008 Share Posted January 14, 2008 mysql_query("INSERT INTO members (id, username, password) VALUES (NULL, '$user', '$pw')") or die('For some reason, we could not process your registration.'); This should be your query line mysql_query("INSERT INTO members (id, username, password) VALUES (NULL, '$name', '$pw')") or die('For some reason, we could not process your registration.'); You are setting the username to $name, not $user Quote Link to comment https://forums.phpfreaks.com/topic/85883-need-help-with-this-registration/#findComment-438520 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.