DonkeyKong Posted February 12, 2013 Share Posted February 12, 2013 Good Day Everyone, I'm a new PHP coder, and so far I'm liking it a the moment I'm creating a simple blog with a little bit of validation and update and create procedures, to a database that has a table for the blogs created I have created 5 different files:index php, display.php. update.php. create php and auth php, so far my code can insert into the database and can also read from it but when it comes to UPDATE it I'm having a nightmare and I dont understand what i am doing wrong even though I have looked for all types of solutions I will attach my files here, as theres too many of them let me know if someone can help me out any help is kindly apprecciated Question.zip Quote Link to comment https://forums.phpfreaks.com/topic/274417-help-with-update-on-a-blog/ Share on other sites More sharing options...
Jessica Posted February 12, 2013 Share Posted February 12, 2013 No offense, but no one wants to look through all of your "too many" files to find your bug. You need to post just the relevant code, and describe the problem besides "it's wrong". Quote Link to comment https://forums.phpfreaks.com/topic/274417-help-with-update-on-a-blog/#findComment-1412081 Share on other sites More sharing options...
DonkeyKong Posted February 13, 2013 Author Share Posted February 13, 2013 No offense, but no one wants to look through all of your "too many" files to find your bug. You need to post just the relevant code, and describe the problem besides "it's wrong". I don't really see the offense there unless you understand any of the words you said as offensive, I was in fact doing what is implied by the site, giving an option to attach multiple files. to a question, perhaps that the part I misunderstood Quote Link to comment https://forums.phpfreaks.com/topic/274417-help-with-update-on-a-blog/#findComment-1412108 Share on other sites More sharing options...
Jessica Posted February 13, 2013 Share Posted February 13, 2013 So, did you bother to read what I said? That's what I get for attempting to be gentle with people. Ignored. Post the relevant code if you want help. Describe your problem. Quote Link to comment https://forums.phpfreaks.com/topic/274417-help-with-update-on-a-blog/#findComment-1412109 Share on other sites More sharing options...
DonkeyKong Posted February 13, 2013 Author Share Posted February 13, 2013 So, did you bother to read what I said? That's what I get for attempting to be gentle with people. Ignored. Post the relevant code if you want help. Describe your problem. Don't get me wrong I'm sure you are the nicest person around here , in fact you deserve a price for being concerned of a noobie I was just kindly answering your statement. at any case the part I think if my code is relevant would be : <div id="theblogs"> <?php if (isset($_POST)) { if (!empty($_POST['submit'])) { $title = $_POST['title']; $content = $_POST['content']; $query = ("UPDATE nothingmovestheblog SET title = '$title', content = '$content' WHERE id= {$_GET['id']}"); $results = $db->query($query); header('Location: index.php'); }else{ ?> <form action = "update.php" method = "post"> <fieldset> <p> <legend>Edit Your Post</legend> <label for= "title">Title</label> <input name = "title" id = "title" value = <?php echo $row['title']?> /> </p> <p> <label for= "content">Content</label> <textarea id="content" name="content" rows="5" required><?php echo $row['content']?></textarea> </p> <p> <input type = "submit" name = "submit" value = "I'd Like To Fix This Post !"/> </p> </fieldset> </form> <?php } } ?> I have a query there that works on MyPHPadmin Im running a table on a database so far on my other php files, Im able to write Into the database(post new blogs) and read from it but when i select an update on an actual post to run the update query on it i get an error: Notice: Undefined index: id in C:\Program Files\.... on line 5 Fatal error: Call to a member function fetch_assoc() on a non-object in C:\Program Files...on line 7 Quote Link to comment https://forums.phpfreaks.com/topic/274417-help-with-update-on-a-blog/#findComment-1412112 Share on other sites More sharing options...
Jessica Posted February 13, 2013 Share Posted February 13, 2013 Okay you're not posting the ID at all, so $_POST['id'] isn't set. You need a hidden input with the posts id. Quote Link to comment https://forums.phpfreaks.com/topic/274417-help-with-update-on-a-blog/#findComment-1412122 Share on other sites More sharing options...
DonkeyKong Posted February 13, 2013 Author Share Posted February 13, 2013 (edited) it is yesh : <?php require('cunnect.php'); $query = "SELECT title, content FROM nothingmovestheblog WHERE id = {$_GET['id']} "; $result = $db->query($query); $row = $result->fetch_assoc(); ?> <!doctype html> <html lang="en"> <head> <meta charset="utf-8" /> <title> Blog </title> <link rel=stylesheet type=text/css href=style.css /> </head> <body> <div id="wrapper"> <div id="header"> <h1> <a href="index.php">My Terrible Awful Blog - New Post</a> </h1> </div> <ul id="menu"> <li> <a href="index.php">Home</a> </li> <li> <a href="archive.php">Archive</a> </li> <li> <a href="create.php" class="active">New Post</a> </li> </ul> <div id="theblogs"> <?php if (isset($_POST)) { if (!empty($_POST['submit'])) { $title = $_POST['title']; $content = $_POST['content']; $query = ("UPDATE nothingmovestheblog SET title = '$title', content = '$content' WHERE id= {$_GET['id']}"); $results = $db->query($query); header('Location: index.php'); }else{ ?> <form action = "update.php" method = "post"> <fieldset> <p> <legend>Edit Your Post</legend> <label for= "title">Title</label> <input name = "title" id = "title" value = <?php echo $row['title']?> /> </p> <p> <label for= "content">Content</label> <textarea id="content" name="content" rows="5" required><?php echo $row['content']?></textarea> </p> <p> <input type = "submit" name = "submit" value = "I'd Like To Fix This Post !"/> </p> </fieldset> </form> <?php } } ?> </div> <div id = "footer">CopyClown - No Rights To Reserve</div> </div> </body> </html> Edited February 13, 2013 by DonkeyKong Quote Link to comment https://forums.phpfreaks.com/topic/274417-help-with-update-on-a-blog/#findComment-1412126 Share on other sites More sharing options...
Jessica Posted February 13, 2013 Share Posted February 13, 2013 Okay you're not posting the ID at all, so $_POST['id'] isn't set. You need a hidden input with the posts id. Quote Link to comment https://forums.phpfreaks.com/topic/274417-help-with-update-on-a-blog/#findComment-1412139 Share on other sites More sharing options...
DonkeyKong Posted February 13, 2013 Author Share Posted February 13, 2013 mmm a hideen input ? mmm you are aware Im calling this from a differen php file correct ? Quote Link to comment https://forums.phpfreaks.com/topic/274417-help-with-update-on-a-blog/#findComment-1412148 Share on other sites More sharing options...
Jessica Posted February 13, 2013 Share Posted February 13, 2013 Clearly I'm wrong since your code works so perfectly. Good luck. Quote Link to comment https://forums.phpfreaks.com/topic/274417-help-with-update-on-a-blog/#findComment-1412149 Share on other sites More sharing options...
DonkeyKong Posted February 13, 2013 Author Share Posted February 13, 2013 God, you are petulant; I was just trying to discuss your hint, obviously I'd like to understand what you are giving me, but sure Quote Link to comment https://forums.phpfreaks.com/topic/274417-help-with-update-on-a-blog/#findComment-1412152 Share on other sites More sharing options...
l0gic Posted February 13, 2013 Share Posted February 13, 2013 (edited) Two things.. One: Don't be such an ass, Jessica doesn't have to help you at all. She's a very nice and helpful person on these forums. Two: Jessica is right. You're not supplying an ID at all. <form action = "update.php" method = "post"> Nothing being passed through the URL/Action/method that $_GET is used with, with is what you're using to try to 'get' the non-passed therefore non-existent ID. You can either change that to: <form action = "update.php?id=$row['id']" method = "post"> Or add a hidden input like this: <input type="hidden" name="id" id="id" value=<?php echo $row['id']?> /> Which pretty much sums up what Jessica hinted at. And please remember this is a 'help' forum, not a 'do it for you or suffer your wrath' forum. Edit: Forgot this forum uses CODE not PHP for code-blocks. Edited February 13, 2013 by l0gic Quote Link to comment https://forums.phpfreaks.com/topic/274417-help-with-update-on-a-blog/#findComment-1412178 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.