gosox345 Posted July 22, 2009 Share Posted July 22, 2009 soo baisically i have a table in a mySQL database called 'pages'. the fields are as follows: 'id' (int(11)) 'name' (varchar(30) 'title' (varchar(30) 'content' (varchar(65466) 'id' is the primary key, set to auto-increment, and is unique. 'name' is just for development proposes to make the database easier to interpret for the developer when looking at the records, i think it might be in my code in maby 1 place, but for the most part this field is useless. 'title' is the what will be echoed in an <h1> tag at the top of the web page. im planning on phassing this out soon and just merging it with the html contained in the 'content field' 'content' is echoed inside a <div>. this contains all sorts of html tags (thus why it has such a high varchar upper-limit) and all of the html code and content of the page other than the site's general layou. so ive incorporated a WYSIWYG in-page html edior called FCKeditor ( http://www.fckeditor.net/ ) that is user-freindly, and is easy to handel posted data with. The code to incorporate the editor to your page is this at the top of your code: <?php include_once("fckeditor/fckeditor.php") ; ?> and this wherever you want the editor to show up: <?php $oFCKeditor = new FCKeditor('FCKeditor1') ; $oFCKeditor->BasePath = 'fckeditor/' ; $oFCKeditor->Value = '<p>HTML content to be edited can go here!</p>' ; $oFCKeditor->Create() ; ?> the content of the editor in the code aboved is suposidly will behave like a normal <INPUT>. the string that is currently set to 'FCKeditor1' will be of equivalence to the 'name property' of the <INPUT> (in other words it should emulate html that looks like this <input name='FCKeditor1'>). the PHP developers guide for FCKeditor can be found here: http://docs.fckeditor.net/FCKeditor_2.x/Developers_Guide/Integration/PHP ---------------------------------------------------------------------------------- NOW, heres my code. edit_pagename.php <?php include_once("fckeditor/fckeditor.php") ; ?> <html> <head> <title>Edit Page: Pagename</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <center><b>Edit Page: Pagename</b></center> <a href='javascript:history.back(-1)'><img src="back.gif" alt="Go Back" border="0" /></a> <a href="logout.php"><img src='logout.gif' onmouseover="this.src='logoutover.gif'" onmouseout="this.src='logout.gif'" alt="Logout" border='0' /></a> <hr> <form action="pages_edit_about_update.php" method="post"> Header: <input type="text" name="title" id="title" value=" <?php mysql_connect("localhost", "database_username", "password") or die(mysql_error()); mysql_select_db("some_database") or die(mysql_error()); $result = mysql_query("SELECT * FROM pages WHERE name='pagename'") or die(mysql_error()); $row = mysql_fetch_array( $result ); echo $row['title']; ?> " /> //^^ this sets the value property of an <input> tag to a specific 'title' value. //see above where i define the fields of my mySQL table <br> <?php mysql_connect("localhost", "database_username", "password") or die(mysql_error()); mysql_select_db("some_database") or die(mysql_error()); $result = mysql_query("SELECT * FROM pages WHERE name='about'") or die(mysql_error()); $row = mysql_fetch_array( $result ); $gotdata = stripslashes($row['content']) ; $oFCKeditor = new FCKeditor('FCKeditor1') ; $oFCKeditor->BasePath = 'fckeditor/' ; $oFCKeditor->Value = $gotdata ; $oFCKeditor->Create() ; ?> <br> <input type="submit" value="Submit"> </form> <br> <a href="techsupport.php">Technical Support</a> </body> </html> edit_pagename_update.php see above in this post where i have what all the fields are about in my database table <?php $mytitle = $_POST['title']; $content = $_POST['FCKeditor1']; $myid = 3; $con = mysql_connect("localhost","database_username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("some_database", $con); mysql_query("UPDATE pages SET content = $content WHERE id = $myid") or die(mysql_error()); mysql_close($con); ?> now this is the beginning value of the 'content' field entry im trying to do a PHP/mySQL update on: '<p>About site can go here!</p>' this is the value im trying to update it to: <p>About site can go here! testingtesting123!</p> ------------------------------------------------ now heres the eror i get on edit_pagename_update.php with posted data contained from edit_pagename.php You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' About site can go here! testingtesting123! WHERE id = 3' at line 1 =/ i think my syntax is correct. im not sure what the problem could be. ive been stumped on this for afew days now and I really want to move on lol. help! i used notepad++ to write all my PHP code if that helps this is my first real PHP project lol, just picking up the language as I go so im stumped Quote Link to comment https://forums.phpfreaks.com/topic/166994-phpmysql-update-help/ Share on other sites More sharing options...
flyhoney Posted July 22, 2009 Share Posted July 22, 2009 $content = mysql_real_escape_string($content); mysql_query("UPDATE pages SET content = $content WHERE id = $myid") or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/166994-phpmysql-update-help/#findComment-880517 Share on other sites More sharing options...
Maq Posted July 22, 2009 Share Posted July 22, 2009 You also need to put single quotes around '$content' in your query. Quote Link to comment https://forums.phpfreaks.com/topic/166994-phpmysql-update-help/#findComment-880519 Share on other sites More sharing options...
gosox345 Posted July 22, 2009 Author Share Posted July 22, 2009 You also need to put single quotes around '$content' in your query. oh! lol quotes around the variables in my query made all the difference! now my code works and updates the mySQL entry! thankyou so much!! Quote Link to comment https://forums.phpfreaks.com/topic/166994-phpmysql-update-help/#findComment-880533 Share on other sites More sharing options...
Maq Posted July 22, 2009 Share Posted July 22, 2009 You also need to put single quotes around '$content' in your query. oh! lol quotes around the variables in my query made all the difference! now my code works and updates the mySQL entry! thankyou so much!! You're welcome, I feel bad you posted such a large thread that probably took 20 minutes Please mark as solved. Quote Link to comment https://forums.phpfreaks.com/topic/166994-phpmysql-update-help/#findComment-880561 Share on other sites More sharing options...
jazlady Posted July 29, 2009 Share Posted July 29, 2009 How can I use FCKEDITOR to update mysql mediumblob content? I enter the information correct to use the fckeditor - my data is being passed successfully to my updateschedule.php but it won't update the datbase. I tried with quotes and without quotes but it still won't work. What am I doing wrong. How do I fix this? <?php include "connect.php"; $updaterunid = $_POST['myrunid']; $updaterun = $_POST['myrun']; $updatecontent = mysql_real_escape_string(trim($_POST['FCKeditor1'])); print $_POST['myrunid']; print $_POST['myrun']; mysql_query("UPDATE schedule SET CONTENT = '$updatecontent' WHERE RUNID = '$updaterunid' ") or die(mysql_error()); mysql_query("UPDATE schedule SET RUN = '$updaterun' WHERE RUNID = '$updaterunid' ") or die(mysql_error()); mysql_query("UPDATE schedule SET RUNID = '$updaterunid' WHERE RUNID = '$updaterunid' ") or die(mysql_error()); include "adminshowschedule.php"; include "closeconnect.php"; ?> soo baisically i have a table in a mySQL database called 'pages'. the fields are as follows: 'id' (int(11)) 'name' (varchar(30) 'title' (varchar(30) 'content' (varchar(65466) 'id' is the primary key, set to auto-increment, and is unique. 'name' is just for development proposes to make the database easier to interpret for the developer when looking at the records, i think it might be in my code in maby 1 place, but for the most part this field is useless. 'title' is the what will be echoed in an <h1> tag at the top of the web page. im planning on phassing this out soon and just merging it with the html contained in the 'content field' 'content' is echoed inside a <div>. this contains all sorts of html tags (thus why it has such a high varchar upper-limit) and all of the html code and content of the page other than the site's general layou. so ive incorporated a WYSIWYG in-page html edior called FCKeditor ( http://www.fckeditor.net/ ) that is user-freindly, and is easy to handel posted data with. The code to incorporate the editor to your page is this at the top of your code: <?php include_once("fckeditor/fckeditor.php") ; ?> and this wherever you want the editor to show up: <?php $oFCKeditor = new FCKeditor('FCKeditor1') ; $oFCKeditor->BasePath = 'fckeditor/' ; $oFCKeditor->Value = '<p>HTML content to be edited can go here!</p>' ; $oFCKeditor->Create() ; ?> the content of the editor in the code aboved is suposidly will behave like a normal <INPUT>. the string that is currently set to 'FCKeditor1' will be of equivalence to the 'name property' of the <INPUT> (in other words it should emulate html that looks like this <input name='FCKeditor1'>). the PHP developers guide for FCKeditor can be found here: http://docs.fckeditor.net/FCKeditor_2.x/Developers_Guide/Integration/PHP ---------------------------------------------------------------------------------- NOW, heres my code. edit_pagename.php <?php include_once("fckeditor/fckeditor.php") ; ?> <html> <head> <title>Edit Page: Pagename</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> </head> <body> <center><b>Edit Page: Pagename</b></center> <a href='javascript:history.back(-1)'><img src="back.gif" alt="Go Back" border="0" /></a> <a href="logout.php"><img src='logout.gif' onmouseover="this.src='logoutover.gif'" onmouseout="this.src='logout.gif'" alt="Logout" border='0' /></a> <hr> <form action="pages_edit_about_update.php" method="post"> Header: <input type="text" name="title" id="title" value=" <?php mysql_connect("localhost", "database_username", "password") or die(mysql_error()); mysql_select_db("some_database") or die(mysql_error()); $result = mysql_query("SELECT * FROM pages WHERE name='pagename'") or die(mysql_error()); $row = mysql_fetch_array( $result ); echo $row['title']; ?> " /> //^^ this sets the value property of an <input> tag to a specific 'title' value. //see above where i define the fields of my mySQL table <br> <?php mysql_connect("localhost", "database_username", "password") or die(mysql_error()); mysql_select_db("some_database") or die(mysql_error()); $result = mysql_query("SELECT * FROM pages WHERE name='about'") or die(mysql_error()); $row = mysql_fetch_array( $result ); $gotdata = stripslashes($row['content']) ; $oFCKeditor = new FCKeditor('FCKeditor1') ; $oFCKeditor->BasePath = 'fckeditor/' ; $oFCKeditor->Value = $gotdata ; $oFCKeditor->Create() ; ?> <br> <input type="submit" value="Submit"> </form> <br> <a href="techsupport.php">Technical Support</a> </body> </html> edit_pagename_update.php see above in this post where i have what all the fields are about in my database table <?php $mytitle = $_POST['title']; $content = $_POST['FCKeditor1']; $myid = 3; $con = mysql_connect("localhost","database_username","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("some_database", $con); mysql_query("UPDATE pages SET content = $content WHERE id = $myid") or die(mysql_error()); mysql_close($con); ?> now this is the beginning value of the 'content' field entry im trying to do a PHP/mySQL update on: '<p>About site can go here!</p>' this is the value im trying to update it to: <p>About site can go here! testingtesting123!</p> ------------------------------------------------ now heres the eror i get on edit_pagename_update.php with posted data contained from edit_pagename.php You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' About site can go here! testingtesting123! WHERE id = 3' at line 1 =/ i think my syntax is correct. im not sure what the problem could be. ive been stumped on this for afew days now and I really want to move on lol. help! i used notepad++ to write all my PHP code if that helps this is my first real PHP project lol, just picking up the language as I go so im stumped Quote Link to comment https://forums.phpfreaks.com/topic/166994-phpmysql-update-help/#findComment-885597 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.