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";

}

}

?>

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";
    }
}

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.