Editing pages/posts

So time for another problem.

I cant get my editPages to work, im not getting any errors but the posts/pages arent getting updated.

I will post everything here, and maby someone can check what i have missed or done wrong.

The editPage.php file:

$query = mysql_query("SELECT * FROM textareas WHERE ID =" . (int) $_GET['id']);
$post = mysql_fetch_assoc($query);
<!DOCTYPE html>
		<title>QSS - admin area</title>
		<link href='http://fonts.googleapis.com/css?family=Droid+Sans:400,700' rel='stylesheet' type='text/css'>
		<link rel="stylesheet" href="admin.css" type="text/css" media="all">

		<div class="wrapper">
			<span>Logged in! Welcome <?php echo $_SESSION['user']; ?></span>
			<a href="logout.php">Logout</a>
			<ul class="topnav">
				<li><a href="index.php">Home</a></li><li><a href="posts.php">Manage Posts</a></li><li><a href="cats.php">Manage Categories</a></li><li><a href="pages.php">Manage Pages</a></li>
			<div class="content">
				<form action="doEditPages.php" method="post">
					<input type="hidden" name="id" value="<?php echo $_GET['id']; ?>" />
					<label for="TextHeading">Header</label><br>
					<input type="text" name="TextHeading" value="<?php echo $post['Heading']; ?>" /><br>
					<label for="TextContent">Content</label><br>
					<textarea name="TextContent"><?php echo $post['Content']; ?></textarea><br>
					<input type="submit" value="Update" name="submit" />

The editPages function:

function editPages($tHeading, $tContent, $id) {
	$id = mysql_real_escape_string($id);
	$query = "UPDATE textareas SET Heading = '$tHeading', Content = '$tContent', WHERE ID = '$id'";

And the doEditPages.php file:


if(isset($_POST['submit'])) {
	if(isset($_POST['TextHeading'])) {
		if(isset($_POST['TextContent'])) {
			header("Location: pages.php");
		} else {
			echo "Please enter some content!";
	} else {
		echo "Please set a header name" ;
} else {
	header("Location: editPages.php");

The problem is occurring due to an invalid syntax in your MySQL UPDATE query. You’ve got a comma after the column set to update (just before the WHERE clause). Simply delete the comma to fix your problem:

$query = "UPDATE textareas SET Heading = '$tHeading', Content = '$tContent' WHERE ID = '$id'";

I’d suggest in future to use MySQL’s native debugging function, mysql_error(), to pick up errors in your SQL syntax.

Thx, yeah i will keep in mind about the mysql_error() function. I have actually used that on most of my sql in this project,… except this one haha:P Have been struggling with this issue for hours :stuck_out_tongue: