SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Feb 2013
    Posts
    289
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    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:

    Code HTML4Strict:
    <?php 
    $query = mysql_query("SELECT * FROM textareas WHERE ID =" . (int) $_GET['id']);
    $post = mysql_fetch_assoc($query);
    ?>
    <!DOCTYPE html>
    	<head>
    		<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">
    	</head>
     
    	<body>
    		<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>
    			</ul>
    			<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" />
    				</form>
    			</div>
    		</div>
    	</body>
     
    </html>

    The editPages function:

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

    And the doEditPages.php file:
    Code PHP:
    <?php
    include('includes.php');
     
    if(isset($_POST['submit'])) {
    	if(isset($_POST['TextHeading'])) {
    		if(isset($_POST['TextContent'])) {
    			editPages($_POST['TextHeading'],$_POST['TextContent'],$_POST['id']);
    			header("Location: pages.php");
    		} else {
    			echo "Please enter some content!";
    		}
    	} else {
    		echo "Please set a header name" ;
    		include('editPages.php');
    	}
    } else {
    	header("Location: editPages.php");
    }

  2. #2
    SitePoint Zealot
    Join Date
    Feb 2012
    Location
    United Kingdom
    Posts
    113
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    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:
    PHP Code:
    $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.

  3. #3
    SitePoint Addict
    Join Date
    Feb 2013
    Posts
    289
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by tpunt View Post
    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:
    PHP Code:
    $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 :P


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •