Jump to content

Display and Edit data in textarea form


jtjtjthey

Recommended Posts

 

      Hi all! I want to create a textarea form not only to display the user comment data from a database but also allows the commenter to edit their comment and save it into the database. I know how to display the data in textarea form but after clicking the save button the data has been erased in the database.

 

      Here is the coding for textarea form:

 

 

<?

$mode=$_GET['mode'];

if($mode=='update')

{

include("../connection/connection.php");

$id=$_GET['id'];

 

$sql0="SELECT * FROM directory WHERE id='$id'";

$search_result0=mysql_query($sql0);

 

while($row=mysql_fetch_array($search_result0))

{

 

$id=$row['id'];

$name=$row['name'];

$department=$row['department'];

$position=$row['position'];

// $extension=$row['extension'];

$assignation_starts=$row['assignation_starts'];

$assignation_ends=$row['assignation_ends'];

$status=$row['status'];

$comment=$row['comment'];

 

}

}

?>

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<title>Comment Box</title>

<style type="text/css">

<!--

.style1 {font-size: 12px}

.style2 {font-size: 18px; }

-->

</style></head>

 

<body>

<table width="440" height="225" border="1">

  <tr>

    <td width="430" align="center" valign="top"><p class="style1"> </p>

    <p align="center" class="style2">Comment    </p>

<form name="comment" method="post" action="comment_process.php?mode=update">

  <p>

  <input type="hidden" name="id" id="id" value="<? echo $id; ?>">

  </p>

  <p>

    <textarea name="textarea"><? echo $comment; ?></textarea>

  </p>

  <p align="center" class="style2">

      <input type="submit" value="Save" onClick="window.close()">

      <input type="submit" name="Submit2" value="Cancel">

    </p></form></td>

  </tr>

</table>

</body>

</html>

 

      Hope you guys can help.

 

 

     

Link to comment
https://forums.phpfreaks.com/topic/116916-display-and-edit-data-in-textarea-form/
Share on other sites

hi,

 

for my online game i have a thing called notepad where you can save allyour notes this is my php code for it, and it may be a great help to your problems:

 

<?php
if(isset($_POST['Write'])){

$result = mysql_query("UPDATE login SET note_pad='".mysql_real_escape_string($_POST['note_pad'])."' WHERE id='" .mysql_real_escape_string($_SESSION['user_id']). "'") 
or die(mysql_error());

echo "Your Note(s) have been saved.<br>";

$note_pad = $_POST['note_pad'];

}// update quote.
?>

 

and this is my text area:

 

 <textarea name="note_pad" rows="50" class="textbox" id="note_pad" style='width: 98%;'><?php echo htmlspecialchars(stripslashes($note_pad)); ?></textarea>

hi,

 

for my online game i have a thing called notepad where you can save allyour notes this is my php code for it, and it may be a great help to your problems:

 

<?php
if(isset($_POST['Write'])){

$result = mysql_query("UPDATE login SET note_pad='".mysql_real_escape_string($_POST['note_pad'])."' WHERE id='" .mysql_real_escape_string($_SESSION['user_id']). "'") 
or die(mysql_error());

echo "Your Note(s) have been saved.<br>";

$note_pad = $_POST['note_pad'];

}// update quote.
?>

 

and this is my text area:

 

 <textarea name="note_pad" rows="50" class="textbox" id="note_pad" style='width: 98%;'><?php echo htmlspecialchars(stripslashes($note_pad)); ?></textarea>

 

 

 

 

 

Thanks Pyro for the reply. I've tried the code you have posted here but the output is still the same. After clicking the Save button the database doesnt update the data.

 

            Here's another php file code used to process update the data name comment_process.php:

 

 

<?

include("../connection/connection.php");

$mode=$_GET['mode'];

if($mode=="update")

{

$id=$_POST['id'];

$comment=$_POST['comment'];

$sql0="UPDATE directory SET comment ='$comment' WHERE id='$id'";

mysql_query($sql0);

//echo $sql0;

 

header("Location:user.php");

}

?>

 

 

is this for public view or just personal, if it is just personal i can give you the du,p aswell so yuo can use that code

 

 

      Yes! I've made it! Simply change the textarea "name=textarea1" to "name=comment" and done! Anyway thanks for the reply, Pyro. You made my day  ;D

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.