Jump to content
Larry Ullman's Book Forums

Deaddog

Members
  • Content Count

    47
  • Joined

  • Last visited

Community Reputation

0 Neutral

About Deaddog

  • Rank
    Member
  1. Maybe you need to change: "js/tinymce/tinymce.min.js to "tinymce/js/tinymce.min.js" ? I think it is setup this way by default. Another thing, make sure your textarea is the same as the selector: "#content". It could be that you need to remove the # sign to match the textarea id in the form.
  2. You got me there, I had that one coming . I thought you went sort of easy on me, but you added a little salt in the wound at the end there with: It must be great to just whip up something like this in 30 minutes. A lifetime of practice I suppose. In my case, I spent a fair amount of time installing and getting the hang of the quick_form2, and really like it. Hopefully your example will sort of align with the code that the book uses. I'm really looking forward to your example, but take your time there is no big rush. I mean if you have to use 45 minutes....by all means. All joking aside, thanks so far.
  3. This forum claims it will "translate geek into English", but I have to say in this case it has gone from geek to just another version of geek. Unfortunately, on this specific oop forum (for this book), I have not read any success stories of someone implementing a registration form using oop techniques. The forum user senso attempted it, but never finished or never re-posted. I assume that user gave up due to frustration. I don't plan on doing that, I haven't spent hundreds of hours over the years and purchase four Ullman books to quit. The procedural way from PHP and MySQL for Dynamic Web Sites is what I have used for all my websites up until now. That book had a great example of user registration. I bought PHP Advanced and OOP in order to take it to the next level, but this is not happening. The book does not contain a registration form example. I'm trying to pursue, not just posting and expecting to be spoon fed the answers. I thought I had made progress earlier in this post by checking for existing email addresses and username, but I was wrong. I appreciate all the help I have received on this forum, it's a great forum to compliment a lot of excellent books. In this case, Larry or one of the other experts here, can you please post an example of a registration form code? I need someone to show a good example of a registration form using the oop techniques from Chapter 9. I've been working on this for one month, I'm learning a lot about oop, but still cannot get the registration form to work. Mainly because I can't get the ->rowCount() to work in order to check for existing users.
  4. Step 1) Beg, borrow, steal, buy, fabricate or otherwise obtain a rubber duck (bathtub variety) Step 2) Place rubber duck on desk and inform it you are just going to go over some code with it, if that's all right. Step 3) Explain to the duck what your code is supposed to do, and then go into detail and explain your code line by line Step 4) At some point you will tell the duck what you are doing next and then realise that that is not in fact what you are actually doing. The duck will sit there serenely, happy in the knowledge that it has helped you on your way. Note: In a pinch a coworker might be able to substitute for the duck, however, it is often prefered to confide mistakes to the duck instead of your coworker. When I remove the getValue() then the error is number of bound variables does not match number of tokens. The duck just told me I was crazy.
  5. Continuing on, the part of the registration form that checks the username and email now works, using the first prepared statement. The next part is to insert the data which is, usertype, *username, *email, *pass, active, dateAdded. Those marked with * come from quickform2. usertype, active (random activation code) are giving me trouble. Below is the code I have tried: $q = 'INSERT INTO users (usertype, username, email, pass, active, dateAdded) VALUES (:usertype, :username, :email, pass=SHA1(:pass), :active, NOW()'; $usertype = 'publicUser'; $active = md5(uniqid(rand(), true)); $stmt = $pdo->prepare($q); //$pdo->bindParam(':ustertype',$usertype); $stmt->bindValue(':active',$active); $stmt->bindValue(':usertype',$usertype); $r = $stmt->execute(array(':usertype'=>$usertype->getValue(),':username' =>$username->getValue(), ':email' =>$email->getValue(), ':pass' =>$password->getValue(),':active'=>$active->getValue())); The error I receive is, Call to a member function getValue() on a non-object . Despite the fact that there are many tutoriols out there on the net I can't find anything that seems to work in my case. How do I get this error to go away to make the insert?
  6. I'm using var_dump($r) to try and troubleshoot this. Why does this query return boolean false? (regardless of what values I put in the form) if ($form->validate()) { $q = "SELECT COUNT(email) FROM users WHERE username=$username OR email=$email"; $r = $pdo->query($q); And this query return an object? (This works fine, there is no form input) //This is from Chapter 9, index.php) try{ $q = 'SELECT id, title, content, DATE_FORMAT(dateAdded, "%e %M %Y") AS dateAdded FROM pages ORDER BY dateAdded DESC LIMIT 1'; $r = $pdo->query($q); And this query return only boolean true? if ($form->validate()) { $q = 'SELECT COUNT(email) FROM users WHERE username=:username OR email=:email'; $stmt = $pdo->prepare($q); $r = $stmt->execute(array(':username'=>$username->getValue(), ':email'=>$email->getValue())); I'm just not getting this. For the first and the last examples, I've tried loads of different combinations of if($r && $r->rowCount() == 0){, but nothing seems to work. I've also tried if($r ->fetchColumn() == 0){ ... On a positive note, I did manage to learn a bit more about quickforms2, regex and compare, very nice. I need assistance to get this registration form email and username check through my thick head!
  7. So, I have tried to use the getValue() like this, however, it produces two errors: Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens and Call to a member function fetchColumn() on a non-object'' Why? $q = 'SELECT COUNT(email) FROM users WHERE email=:email'; $stmt = $pdo->prepare($q); $r = $stmt->execute(array(':username'=>$username->getValue(), ':email'=>$email->getValue())); if ($r->fetchColumn() > 0){ I know you said in your previous post to use $pdo->query($q), but I'm struggling to figure out how to do this and at the same time get the input values from the form...So, here I am stuck!
  8. I thought that email value comes from the form? $email = $form->addElement('text','email');
  9. Thanks for the help so far. Why does A not work with $r->rowCount and B work? A is my attempt at making the registration form verify email addresses previously registered, email=:email comes from user input using QuickForms2 B is from Chapter 9, index.php. if ($form->validate()) { //A) This does not work with $r->rowCount($q): $q = 'SELECT COUNT(*) FROM users WHERE email=:email'; //B) This works with $r->rowCount($q): $q = 'SELECT id, title, content, DATE_FORMAT(dateAdded, "%e %M %Y") AS dateAdded FROM pages ORDER BY dateAdded DESC LIMIT 1'; $r = $pdo->query($q); //check that some rows were returned. if($r && $r->rowCount() > 0){ Here is the form code: require('HTML/QuickForm2.php'); $form = new HTML_QuickForm2('RegistrationForm'); //Add the desired username field. $username = $form->addElement('text', 'username'); $username ->setLabel('Desired Username'); $username ->addFilter('trim'); $username ->addRule('required','Please choose your desired username.'); //Add the email address field. $email = $form->addElement('text','email'); $email->setLabel('Email'); $email->addFilter('trim'); $email->addRule('required','Please enter your email address.'); //Add the password field. $password =$form->addElement('password','pass'); $password->setLabel('Password'); $password->addFilter('trim'); $password->addRule('Required','Please create a password.');
  10. So I'm trying to make a simplified version of checking the email against the existing users, see code snippet: (For registration purposes). if($_SERVER['REQUEST_METHOD']=='POST'){ // Validate the form data: if ($form->validate()) { $results = $pdo->query('SELECT id FROM users WHERE email=:email'); //Review page 262 if ($results->rowCount() == 1){ echo 'Sorry, that username or email is previously registered!'; include('includes/header.inc.php'); include('views/register.html'); include('includes/footer.inc.php'); exit(); I keep getting the error, "Call to a member function rowCount() on a non-object..." I'm following or at least think I'm following the book, referring to Chapter 8, page 262 in my book. $results->rowCount() should be equivalent to mysqli_num_rows, but I'm not getting it to work. What am I doing wrong? Jason
  11. For the sake of simplicity, I think I'm leaning towards adding the active to the user table. I'm going to make a page called registration.php. The script will check the email against the users table using a prepared statement. If that email is not previously registered it will insert the name, email, password and activation code on a second prepared statement. Is this basically what needs to happen? So the first hurdle is getting the oop/pdo equivalent of this: $q = "SELECT user_id FROM users WHERE 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) { //Available. //Create the activation code. $a = md5(uniqid(rand(), true));
  12. Thanks for the advice Larry. I will make an attempt at this and whatever I happen to conjure up, I'll post. If nothing else, I'm sure it will give some of the experienced OOP developers a chuckle . We'll see.
  13. This will be my first attempt to really dig into oop on my own, without copying the code directly from the book. It seems very overwhelming. Using the CMS from Chapter 9, I will try to expand on the registration form in order to add an activation code. The goal is that when a new user registers, an activation link will be sent by email. I know this procedural method from one of Larry's previous books. For the oop, I really need some help to get things started in the right direction. So far, I've added a column to the users table called active. A char(32), default NULL. Added an attribute $protected active = null to class User(). -Made a registration form with the following fields: desired username, email, password and retype password fields. Any general advice on how I should proceed would be very helpful.
  14. The answer to this is simple: Took the dog for a walk, came home and re-read through chapter 8, the part where it says "Note that this does assume that the classes and class files use the same exact names( minus the extensions)." So I just changed the file classes/page.php to classes/Page.php. Such details. Strange that it worked fine on local machine with the lowercase page.php, but not on the live server. Problem solved.
×
×
  • Create New...