Jump to content

Update database content with TinyMCE


Raf1k1

Recommended Posts

Hi,

 

I'm having trouble using TinyMCE to update some content in my database.

It's taking me to update.php and displaying a blank page. I thought maybe it's not connecting to the database so I tried using connection script in the update.php file instead of requiring it from another file but it made no difference.

 

Here's the code from the editAbout file:

<?php

if(isset($_GET['message'])){
echo "<p><font color='red'>Update Successful!</font></p>";
}

// Pull About page content from database
$sql = "SELECT about_id, about_content FROM about";
$result = $conn->query($sql) or die(mysqli_error());
if($result){
$row = $result->fetch_object();
echo '<form method="post" action="update.php">';
echo '<input type="hidden" name="id" value="'.$row->about_id.'" />';
echo '<textarea name="about_content" cols="80" rows="20">';
echo $row->about_content;
echo '</textarea>';
echo '<input type="submit" name="content" value="Update Content" />';
echo '</form>';
}
?>

 

and here's the update.php code:

// If user pressed "Update Content" button
if(isset($_POST['editContent'])){
// Update page content
require("./connection.php");
$about_content = $_POST['content'];
$about_id = $_POST['id'];
$sql = "UPDATE about SET about_content='$about_content' WHERE about_id='$about_id'";
$result = $conn->query($sql) or die(mysql_error());
if($result){
	header("location: adminAbout.php?message=1");
}
}

 

Can anyone see where I went wrong?

Link to comment
https://forums.phpfreaks.com/topic/193265-update-database-content-with-tinymce/
Share on other sites

tinyMCE is for inline editing of pages on your site. Why are you using it to try to manage DB data? For that you make a page that grabs the existing data and then you either edit it or remove it then process it into the DB again.

 

Use the pages you have(editabout.php and update.php) without invloving tinyMCE and you should be able to do what you are trying.

 

 

HTH

Teamatomic

i changed the following

echo '<input type="submit" name="content"

 

to

echo '<input type="submit" name="editContent"

 

which didn't seem to do anything but after adding your error reporting code it's seems to be working now which is odd.

 

@above: I'm pretty new to PHP and was wanting to see what I could do with it. I'm guessing you're right as I don't really know much about it and will try doing it the way you've suggested in future.

 

edit: thanks  jl5501. It's working the way it should now. Much appreciated  :D

 

I realise that I probably shouldn't be storing the entire contents of a page in one field but I was wanting to start simple and build up to something more complicated later on.

 

Thanks once again.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.