Jump to content

problem updating mysql


bagmaendene

Recommended Posts

Hello all,

 

I have a little problem updating my sql.

This is my page:

<?php
session_start();

include_once('../includes/connection.php');
include_once('../includes/article.php');

$article = new Article;

if (isset($_SESSION['logged_in'])) {
if (isset($_GET['id'])) {
$id = $_GET['id'];
$query = $pdo->prepare('SELECT FROM articles WHERE article_id =?');
$query->bindValue(1, $id);
$query->execute();

header('Location: edit.php');

}


$articles = $article->fetch_all();


?>
<html>
<head>
</head>
<body>
<h4>Edit Article</h4>

<?php if (isset($error)) { ?>
<small style="color:#aa0000"><?php echo $error; ?>
<?php } ?>




<form action="edit.php" method="post">
<?php foreach ($articles as $article) { ?>

ID: <input type="text" name="id" value="<?php echo $article['article_id']; ?>"><br /><br />
Article Title: <b><?php echo $article['article_title']; ?></b> <br /><br />
 Text: <br/> <textarea rows="15" name="article_content" cols="50"><?php echo $article['article_content']; ?></textarea><br /><br />
 <input type="submit" value="Edit Article"> <br/ >
 <?php }

if( isset($_POST['article_content']))
{
$newcontent = $_POST['article_content'];
$id = $_POST['id'];
$query = $pdo->query("UPDATE article_content SET article_content='$newcontent' WHERE id='$id'");

}



?>
</form>



<a href="index.php">← Back</a>

</body>
</html>
<?php
} else {
header('Location: index.php');
}



?>

Here is a screen of my database: http://imageshack.us...ing2013021.png/

Could somebody please help me?

 

-edit-

Its about the article_content row.

That has to be updated.

 

Thnx

Edited by bagmaendene
Link to comment
Share on other sites

Your form contains many textboxes and textareas, all named "id" and "article_content". They will all overwrite each other and you'll only get the value from the last one in the form.

 

You can

a] Write a form for every article (move the

inside the loop) which only lets you update one article at a time, or

b] Make a smarter, more complicated form that lets you update more than one at a time.

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.