Jump to content

invision2

New Members
  • Posts

    8
  • Joined

  • Last visited

    Never

Everything posted by invision2

  1. Eeeek. I'm a little bit confused I'm afraid. How would your code fit in with my own application? Should I rewrite my own code? Would it help if I PM'd you my current app so far? Thanks again
  2. Just out of interest, the final code I have: public function editEntry($id,$title) { $sql = "UPDATE entries SET title=:title WHERE id=:id LIMIT 1"; if ($stmt = $this->_db->prepare($sql)) { $stmt->bindParam(':title', $title, PDO::PARAM_STR); $stmt->bindParam(':id', $id, PDO::PARAM_INT); $stmt->execute(); $stmt->closeCursor(); return true; } if ($stmt->execute() == false) { user_error(print_r($this->_db->errorInfo() , 1)); return false; } if ($stmt->rowCount() == 0) { user_error("No rows updated."); error_log(print_r($stmt->debugDumpParams() , 1)); return 0; // allow client code to differntiate between false & zero } $stmt->closeCursor(); return true; } user_error(print_r($stmt->errorInfo() , 1)); return false; } how would I tell the user if it was a successful update, or not. Is there anything obvious missing from this script, any holes you can see? Also, is there a way I can validate the text so it must be greater than 5 characters? Should I do this in my editentry script, or in the function? Really appreciate the help. Many thanks again.
  3. Got it working Oh man, so easy too. public function editEntry($title, $id) had to be: public function editEntry($id,$title) because of the way I was bringing in the arguments from my editentry script. Thanks for the help guys. I may be back shortly
  4. Thanks for the reply guys. Error reporting doesn't seem to suggest anything is wrong I've really no idea where I've gone wrong. 9three, could I possibly email over the files to you to have a closer look, I would really appreciate it. Good point abazoskib. I'm just wanting to improve my coding style, as right now, it's not so hot. I thought OOP would save me a lot of time in the long run too.
  5. It's a good call. But the UPDATE query doesn't seem to work at all When I submit I'd hope to check if any rows were affected. If so, it'd say 'Success' and if not 'Fail', load form. Am I missing something obvious from the script that's stopping it working? I think I've thought of everything
  6. Many thanks for the quick reply. I've updated the function to include the 2 arguments, but now when I submit, it just goes blank. edit: When I submit the form, the header remains, but the rest of the page is blank. Is there anything else you can spot wrong with the script? Do I need to give values to $title and $id in my editentry.php script? Really appreciate the help.
  7. Could you not just change your CSS about a bit? So your Header HTML is further down in the HTML source, but CSS positions it in the header position on the page I'd be happy to help knock up some CSS for you
  8. Hi, I've been doing some really poor PHP for about 3-4 years now and with the new year, I want to do it the better way I've been dabbling with some OOP so far this weekend, and happy with the results. Managed to create an 'AddEntry' class and added a record to my table in the database. However, I'm having some issues with an 'Edit Entry' script I'm trying, and wondered if I could get some assistance. // a snippet from my blog class public function editEntry() { $sql = "UPDATE entries SET title=:title WHERE id=:id LIMIT 1"; if ($stmt = $this->_db->prepare($sql)) { $stmt->bindParam(':title', $title, PDO::PARAM_STR); $stmt->bindParam(':id', $id, PDO::PARAM_INT); if ($stmt->execute() == false) { user_error(print_r($this->_db->errorInfo() , 1)); return false; } if ($stmt->rowCount() == 0) { user_error("No rows updated."); error_log(print_r($stmt->debugDumpParams() , 1)); return 0; // allow client code to differntiate between false & zero } $stmt->closeCursor(); return true; } user_error(print_r($stmt->errorInfo() , 1)); return false; } <?php // my edit_entry.php script include_once "common/base.php"; $pageTitle = "Edit Entry"; include_once "common/header.php"; if(!empty($_POST['title'])): include_once "inc/class.blog.inc.php"; $entry = new BlogEntries($db); /*echo $entry->editEntry();*/ $result = $entry->editEntry($_POST['id'], $_POST['title']); else: include_once "inc/class.blog.inc.php"; $entry = new BlogEntries($db); ?> <h2>Edit Entry</h2> <form method="post" action="editentry.php?id=<?php echo htmlspecialchars($_GET['id']); ?>" id="registerform"> <div> <label for="title">Title:</label> <input type="text" name="title" id="title" value="<?php echo $entry->getEntry(); ?>" /><br /> <input type="submit" name="register" id="register" value="Edit" /> <input type="hidden" name="token" value="<?php echo $_SESSION['token']; ?>" /> <input type="hidden" name="id" value="<?php echo $_GET['id']; ?>" /> </div> </form> <?php endif; include_once 'common/close.php'; ?> Basically, if I make a change to the value in the input field and submit, it always gives me the output: user_error("No rows updated."); Is there something obvious I'm missing from either of the 2 scripts? I'm just wanting the script to update the table. I would really appreciate any pointers with this. Thank you
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.