我正在尝试提交包含textarea字段的表单。
表单是较大表的一部分,其值包含在索引页面中。
我想从另一个页面提交textarea,其中填充其他字段,并使用数据库中提交的文本更新textarea字段。
如您所见,除了PM状态列之外,已经填充了值。
这是我的代码:
<?php
$title = $_GET['title'];
$result = mysqli_query($con, "SELECT * FROM projects WHERE title='".$title."'");
if($result === FALSE) {
mysqli_error($con);
} else {
echo '<div class="well">
<table class="table">
<thead>
<tr>
<th style="width: 10%;">Project</th>
<th style="width: 5%">Author</th>
<th style="width: 10%">Topic</th>
<th style="width: 13%">Track</th>
<th style="width: 30%">Description</th>
<th style="width: 22%">Screenshots</th>
<th style="width: 5%">PM Status</th>
<th style="width: 5%">Status</th>
</tr>
</thead>';
foreach( $result as $row ) {
echo '<tbody>';
echo '<tr>';
echo '<td style="color: #5584ff; font-weight: bold;"><a href="project.php?title='.$row['title'].'">' .$row['title']. '</a></td>';
echo '<td>' .$row['author']. '</td>';
echo '<td>' .$row['topic']. '</td>';
echo '<td>' .$row['track']. '</td>';
echo '<td>' .$row['description']. '</td>';?>
<?php
if($row['file'] != '') {
echo '<td><a href="uploads/'.$row['file'].'"><img src="uploads/'.$row['file'].'" style="max-width: 100%;" /></a></td>';
}
?>
<?php
echo '<form name="savestatus" id="savestatus" action="validarestatus.php" method="post">';
echo '<td><textarea name="status" value="'.$_SESSION['status'].'" class="textarea"> '.$_SESSION['status'].' </textarea></td>';
echo '<td><input type="submit" class="add-project" style="border: none" value="Save Status">';
echo '</form>';
?>
<?php
echo '</tr>';
echo '</tbody>';
}
echo '</table>';
echo '</div>';
}
?>
表单操作中的页面:
<?php
require_once('secure/config.php');
$_SESSION['status'] = addentities($_POST['status']);
if(($_SESSION['status']) == '') {
echo "Data was not added\n";
} else
{
if(isset($_POST['submit']))
{
mysqli_query($con, "INSERT INTO `projects (`status`) VALUES ('".$_SESSION['status']."') WHERE id='".$_SESSION['id']."'");
}
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL=projects.php">';
}
$_SESSION['status'] = '';
?>
addentities功能:
function addentities($data){
if(trim($data) != ''){
$data = htmlentities($data, ENT_QUOTES);
return str_replace('\\', '\', $data);
} else return $data;
}
感谢您的帮助!