I’ve managed to implement a simple TinyMCE editor on my site and have it call using mySQL database. My problem Im having now is getting the DB to overwrite the contents already stored inside with what is being posted?
I simply want to overwrite the table contents (within the column) with what is being inserted.
Here is my code:
<!--- CONNECT TO THE DATABASE------>
<?php
$con = mysql_connect("localhost","root","jdkldk8%by");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("cms", $con);
$sql="INSERT INTO tinymce (contents, contact, slider, resources)
VALUES
('$_POST[contents]','$_POST[contact]','$_POST[slider]','$_POST[resources]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
?>
<!--- END DATABASE SETTINGS ----->
[ View your changes here ]
///////////////////////////////////////////////////////////////////////////////////////
Well… i tried again but its still not posting all fields to the DB! only updating 1.
<!--- CONNECT TO THE DATABASE------>
<?php
require_once('db.php');
$contents=$_POST['contents'];
$contact=$_POST['contact'];
$slider=$_POST['slider'];
$resources=$_POST['resources'];
$id='1';
$sql="UPDATE tinymce SET `contents`='$contents', `contact`='$contact', `slider`='$slider', `resources`='$resources' WHERE id='$id'";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "Saved!";
mysql_close($con);
?>
<!--- END DATABASE SETTINGS ----->
You want to use UPDATE, not INSERT, to update a previously created MySQL column.
Try editing a column using phpmyadmin and copying the resulting code from their MySQL code viewer.