Jump to content

problem inconu


aboulmaaly

Recommended Posts

please help me here is my script and I always get the response "Failed update post"

-----------------------

edit.php

------------------------------------------------------------------------------------------------

<?php
include_once './includes/config.php';
?>
<!DOCTYPE html>
<html dir="ltr">
<head>
<meta name="author" content="" />
<meta charset="utf-8" />
<link rel="stylesheet" href="css/style.css" type="text/css" />
<title>edit content</title>
</head>
<body>
<?php
if(isset($_GET['id'])){
$result = mysql_query("SELECT * FROM news WHERE id=".$_GET['id']);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
?>
<form method="post" action="editt.php">
<input type="text" name="title" value="<?php echo $row['title']; ?>" /><br/>
<textarea name="subject" rows="10" cols="50" ><?php echo $row['subject']; ?></textarea>
<input type="hidden" name="id" value="<?php echo $row['id']; ?>" /><br/>
<input type="submit" name="submit" value="edit" />
</form>
<?php
}
else {
?>
<?php
$query = mysql_query("SELECT * FROM news ORDER BY id");
while ($row = mysql_fetch_array($query)) {
?>
<div style="text-align: center">
<h3><?php echo $row['title']; ?></h3>
<span><a href="edit.php?id=<?php echo $row['id']; ?>">edit</a></span>
</div>
<?php
}}
?>
</body>
</html>
-----------------------------------------------------------------------------------------------------------
editt.php
--------------------------------------------------------------------------------------------------------------
<?php
include_once './includes/config.php';
if(isset($_POST['submit'])){
$id = htmlspecialchars(addslashes(trim($_POST['id'])));
$title = htmlspecialchars(addslashes(trim($_POST['title'])));
$subject = htmlspecialchars(addslashes(trim($_POST['subject'])));
$query = "UPDATE news SET title=".$title.", subject=".$subject." WHERE id=".$id;
$result = mysql_query($query);
if($result){
echo 'success update post';
echo '<a href="index.php">home</a>';
}
else {
echo 'Failed update post';
echo '<a href="edit.php">edit</a>';
}
}
?>
----------------------------------------------------------------------------------------------------------------

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...