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

Link to comment
https://forums.phpfreaks.com/topic/274699-problem-updating-mysql/
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.

Archived

This topic is now archived and is closed to further replies.

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