I'm trying to learn to update a table in mysql from a textarea. <textarea rows="30" cols="60" name="content" /><?php echo $row['content'] ?></textarea>. This is the mysql command i use. mysql_query("UPDATE pages SET content='$content' WHERE id='$id'");. I'm not sure why it's not doing it. Also I'm using tinymce as the editor and the area is hard to edit. If anyone has any suggestions please let me know.
Update via Textarea
Started by ghost2012, Dec 16 2010 12:13 PM
2 replies to this topic
#1
Posted 16 December 2010 - 12:13 PM
|
|
|
#2
Posted 16 December 2010 - 12:54 PM
#3
Posted 16 December 2010 - 01:06 PM
I'm using $_POST. I'm trying to be able to edit content from mysql via a <textarea> tag kinda like the (edit) buttons here on the forum.
This is the code I'm using.
This is the code I'm using.
<?php
session_start();
if(!$_SESSION['username']){
header('Location: ../login.php');
} else {
include_once '../functions/index.php';
$sql = "SELECT * FROM pages;";
$result = mysql_query($sql);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
tinyMCE.init({
mode : "textareas"
});
</script>
<style type="text/css">
.button {
border: 1px solid #006;
background: #9cf;
}
</style>
</head>
<body>
<?php
if($_POST['updatePost'])
{
$id;
$content;
$id = $_POST['id'];
$content = $_POST['content'];
mysql_query("UPDATE pages SET content='$content' WHERE id='$id'");
exit;;
}
if($_POST['edit'])
{
$id = $_POST['id'];
$sql = "SELECT * FROM pages WHERE id='$id'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
?>
<form method="post">
<fieldset style="width:500px;">
<legend>Front Page</legend>
<table>
<tr>
<td width="20%"><label>Title:</label></td>
<td><?php echo $row['title'] ?></td>
</tr>
<tr>
<td width="20%" valign="top"><label>Content: </label></td>
<td><textarea rows="30" cols="60" name="content" /><?php echo $row['content'] ?></textarea></td>
<input type="hidden" name="id" value="' . $row['id'] . '" />
</tr>
<tr>
<td></td><td align="center"><input type="submit" name="updatePost" id="updatePost" value="Update Post" style="width:200px;" class="button"/></td>
</tr>
</table>
</fieldset>
</form>
<?php
exit;
}
}
?>
<form method="post">
<p>Edit content by entering number
<input type="text" name="id" id="id" style="width:30px" />
<input type="submit" name="edit" id="edit" value="Edit" class="button"/>
</p>
</form>
<?php
echo '<table';
while($row=mysql_fetch_array($result))
{
echo '<tr>
<td width="50">Title:</td>
<td width="400">' . $row['title'] . '</td>
<td>' . $row['id'] . '</td>
</tr>';
}
echo '</table>';
?>
</body>
</html>
<?php
}
?>
Edited by Alexander, 16 December 2010 - 02:44 PM.
(code tags #)


Sign In
Create Account


Back to top









