Simsonite Posted November 12, 2008 Share Posted November 12, 2008 h i am trying to create a CMS for my website, however i am having problems with MySql Queries. Here is the code <?php // Check whether a form has been submitted. If so, carry on if ($HTTP_POST_VARS){ // Validate the entries $validator = new Validator(); $validator->validateGeneral($HTTP_POST_VARS['thearticle'],'Article'); // Check whether the validator found any problems if ( $validator->foundErrors() ){ echo 'There was a problem with: <br>'.$validator->listErrors('<br>'); // Show the errors, with a line between each }else{ // Create an SQL query (MySQL version) // The 'addslashes' command is used 5 lines below for added security // Remember to use 'stripslashes' later to remove them (they are inserted in front of any // special characters $content = $HTTP_POST_VARS['thearticle']; $insertQuery = "UPDATE 'cmscontent' SET thearticle='$content' WHERE ID = '1'"; // Save the form data into the database //!!!!!!!!!!!!! THIS IS LINE 22!!!!!!!!!!!!! if ($result = $connector->query(UPDATE 'cmscontent' SET 'thearticle'='$content' WHERE 'ID' = '1'));{ // It worked, give confirmation echo '<center><b>Article added to the database</b></center><br>'; else{ // It hasn't worked so stop. Better error handling code would be good here! exit('<center>Sorry, there was an error saving to the database</center>'); } } } ?> </div> <form name="form1" method="post" action="editcontent.php" style="width:730px; margin-left:-4px;"> <p align="center"> <textarea name="thearticle" cols="50" rows="6" id="thearticle" class="mceEditor"> <?php while ($row = $connector->fetchArray($oldcontent)){ echo $row['thearticle']; } ?> </textarea> </p> <p align="center"> <input type="submit" name="Submit" value="Submit"> </p> </form> I am getting the error message Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/dancdoit/public_html/admin/cmsadmin/editcontent.php on line 122 Quote Link to comment https://forums.phpfreaks.com/topic/132484-solved-cms-problems/ Share on other sites More sharing options...
Mchl Posted November 12, 2008 Share Posted November 12, 2008 It says line 122 Quote Link to comment https://forums.phpfreaks.com/topic/132484-solved-cms-problems/#findComment-688846 Share on other sites More sharing options...
Simsonite Posted November 12, 2008 Author Share Posted November 12, 2008 Yer but i am confused on how to solve this problem. Im kind of a begginer at this. Quote Link to comment https://forums.phpfreaks.com/topic/132484-solved-cms-problems/#findComment-688851 Share on other sites More sharing options...
Mchl Posted November 12, 2008 Share Posted November 12, 2008 Well... show us line 122 of editcontent.php (and preferably some lines before) As for line 22: if ($result = $connector->query("UPDATE 'cmscontent' SET 'thearticle'='$content' WHERE 'ID' = '1'")){ There's unnecessary ; before { , AND you're missing "" around the query. Quote Link to comment https://forums.phpfreaks.com/topic/132484-solved-cms-problems/#findComment-688860 Share on other sites More sharing options...
corbin Posted November 12, 2008 Share Posted November 12, 2008 Also, not sure if single quotes are valid around column names in MySQL. `tablename` or just tablename. Quote Link to comment https://forums.phpfreaks.com/topic/132484-solved-cms-problems/#findComment-688910 Share on other sites More sharing options...
Simsonite Posted November 13, 2008 Author Share Posted November 13, 2008 sorry lol line 22 is line 122 =) So what exactly would i need to change this line to? Quote Link to comment https://forums.phpfreaks.com/topic/132484-solved-cms-problems/#findComment-689126 Share on other sites More sharing options...
Mchl Posted November 13, 2008 Share Posted November 13, 2008 to: if ($result = $connector->query("UPDATE `cmscontent` SET `thearticle`='$content' WHERE `ID` = '1'")){ Quote Link to comment https://forums.phpfreaks.com/topic/132484-solved-cms-problems/#findComment-689128 Share on other sites More sharing options...
Simsonite Posted November 13, 2008 Author Share Posted November 13, 2008 Hi i am now getting the error Parse error: syntax error, unexpected T_ELSE in /home/_______/public_html/admin/cmsadmin/editcontent.php on line 127 Quote Link to comment https://forums.phpfreaks.com/topic/132484-solved-cms-problems/#findComment-689196 Share on other sites More sharing options...
Simsonite Posted November 13, 2008 Author Share Posted November 13, 2008 DW solved that problem Quote Link to comment https://forums.phpfreaks.com/topic/132484-solved-cms-problems/#findComment-689197 Share on other sites More sharing options...
Simsonite Posted November 13, 2008 Author Share Posted November 13, 2008 Ok thanks so much for helping me with the last problem. However now i am trying to edit this script to delete content of the data base but it will not delete it. this is the code <?php // DELETE ARTICLES //////////////////////////////////////////////////////////////////// if ($HTTP_GET_VARS['action'] == 'delete'){ // Store the ID of the section to be deleted in a variable $sectionID = $HTTP_GET_VARS['ID']; // Validate the section ID, and if it's ok then delete the section if ( $validator->validateNumber($sectionID,'Section ID') ){ // The validator returned true, so go ahead and delete the section $connector->query('DELETE FROM cmsarticles WHERE ID = '.$sectionID); echo 'Article Deleted <br><br>'; }else{ // The validator returned false, meaning there was a problem echo "Couldn't delete. There was a problem with: ".$validator->listErrors(); } } // LIST ARTICLES ///////////////////////////////////////////////////////////////////// // Execute the query to retrieve articles $result = $connector->query('SELECT ID,title,tagline FROM cmsarticles'); // Get an array containing the results. // Loop for each item in that array while ($row = $connector->fetchArray($result)){ echo '<br>'; echo "Title - {$row['title']}"; echo '<br>'; echo "Description - {$row['tagline']}"; echo '<br>'; echo '<a href="deletenews.php?action=delete&id='.$row['ID'].'"> Delete </a>'; echo '<br>'; echo '<br>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/132484-solved-cms-problems/#findComment-689513 Share on other sites More sharing options...
fenway Posted November 13, 2008 Share Posted November 13, 2008 Ok thanks so much for helping me with the last problem. However now i am trying to edit this script to delete content of the data base but it will not delete it. Your last problem was a PHP issue... this maybe as well. You need to check that you're actually getting into the block that deletes from the DB -- and that the query runs. Quote Link to comment https://forums.phpfreaks.com/topic/132484-solved-cms-problems/#findComment-689623 Share on other sites More sharing options...
Simsonite Posted November 13, 2008 Author Share Posted November 13, 2008 Ok should i repost in the PHP section then? Because im really confused on what to do here. Quote Link to comment https://forums.phpfreaks.com/topic/132484-solved-cms-problems/#findComment-689631 Share on other sites More sharing options...
fenway Posted November 13, 2008 Share Posted November 13, 2008 Ok should i repost in the PHP section then? Because im really confused on what to do here. No, don't report -- check with echo() statements that you're getting where you expect first. Quote Link to comment https://forums.phpfreaks.com/topic/132484-solved-cms-problems/#findComment-689641 Share on other sites More sharing options...
Simsonite Posted November 13, 2008 Author Share Posted November 13, 2008 OK I found out that i am not getting anything for $sectionId im guessing that this $sectionID = $HTTP_GET_VARS['ID']; is the problem Quote Link to comment https://forums.phpfreaks.com/topic/132484-solved-cms-problems/#findComment-689655 Share on other sites More sharing options...
Simsonite Posted November 13, 2008 Author Share Posted November 13, 2008 Fixed thanks for ure help. That tip about using echo to bug fix was really good. PS. sorry im a beginner at Mysql and php im 15 and just started learning. Again Thanks Quote Link to comment https://forums.phpfreaks.com/topic/132484-solved-cms-problems/#findComment-689660 Share on other sites More sharing options...
Mchl Posted November 13, 2008 Share Posted November 13, 2008 PS. sorry im a beginner at Mysql and php im 15 and just started learning. Well, you're starting 8 years earlier than I did. And practice makes perfect Quote Link to comment https://forums.phpfreaks.com/topic/132484-solved-cms-problems/#findComment-689668 Share on other sites More sharing options...
fenway Posted November 13, 2008 Share Posted November 13, 2008 You should be using the $_GET hash, AFAIK. Quote Link to comment https://forums.phpfreaks.com/topic/132484-solved-cms-problems/#findComment-689692 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.