Jump to content

Help With Update on a BLog


DonkeyKong

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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 by DonkeyKong
Link to comment
Share on other sites

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 by l0gic
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.