soo basically 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 layout.
and im using FCKeditor btw
------------------------------------------------------------------------
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!
Re: PHP/mySQL update help
mysql_query("UPDATE pages SET content = '$content' WHERE id = '$myid'") or die(mysql_error());
Additionally, make sure you using addslashes to $content as a safeguard and to make sure quotes and such are escaped properly.
Re: PHP/mySQL update help
I am getting data for the $updaterunid, $updaterun, $updatecontent it shows it on the screen but it won't update the mysql database. Please look at code below to perform update.
Can you help me?