Jump to content

Modify MySQL tables using form back-end of CMS


richeyrich_86

Recommended Posts

Hi am in processes of making a bespoke CMS for a project in uni am having a problem with my scrip basically i have three php files i have content which echos out the database tables i wish to edit with a link to an update_content page when u click on that it bring u too update_content.php which allows the user to modifier the content in the tables but when i hit update am getting a Parse error: syntax error, unexpected T_IF in line 4 of my update_ac file any help would be great

cheers richie

 

<?php

require("includes/connection.php")

// If form button has been pressed then do the following

if(isset($_POST['update'])){

// Get id of post

$id = $_GET['id'];

$header = $_POST['header'];

$content = $_POST['content'];

 

// Update database table

$query = "UPDATE pages SET header = '$header', content = '$content' WHERE id = '$id'";

$result = mysql_query($query);

if ($result){

echo "Successfully edited entry";

} else {

echo "There was error editing entry";

}

}

?>

Link to comment
Share on other sites

Also while not a syntax error, you have a logic error in how you're checking the query's success. mysql_query() will return true for a statement that is executed successfully, but a successful query can affect zero rows. Instead you should use mysql_affected_rows something like:

 

if (!$result = mysql_query($query)) {
    echo 'Database error: ' . mysql_error();
} else {
    if (mysql_affected_rows($result) > 0) {
        echo "Successfully edited entry";
    } else {
        echo "There was error editing entry";
    }
}

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.