richeyrich_86 Posted March 18, 2011 Share Posted March 18, 2011 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"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/231005-modify-mysql-tables-using-form-back-end-of-cms/ Share on other sites More sharing options...
gristoi Posted March 18, 2011 Share Posted March 18, 2011 missing a semi colon on 2nd line. should be: require("includes/connection.php"); Quote Link to comment https://forums.phpfreaks.com/topic/231005-modify-mysql-tables-using-form-back-end-of-cms/#findComment-1189139 Share on other sites More sharing options...
richeyrich_86 Posted March 18, 2011 Author Share Posted March 18, 2011 haha sorry i am now going to find under a big rock cheers for the help Quote Link to comment https://forums.phpfreaks.com/topic/231005-modify-mysql-tables-using-form-back-end-of-cms/#findComment-1189145 Share on other sites More sharing options...
Adam Posted March 18, 2011 Share Posted March 18, 2011 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"; } } Quote Link to comment https://forums.phpfreaks.com/topic/231005-modify-mysql-tables-using-form-back-end-of-cms/#findComment-1189147 Share on other sites More sharing options...
richeyrich_86 Posted March 18, 2011 Author Share Posted March 18, 2011 cheer thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/231005-modify-mysql-tables-using-form-back-end-of-cms/#findComment-1189232 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.