获取textarea值并保留返回值

时间:2015-02-09 08:06:30

标签: php

问题是我无法在页面上保留textarea值 从数据库中获取textarea的值,但不能保留其先前的值。

HTML:

<textarea class="form-control" name="a" rows="3"> </textarea>

PHP:

$_SESSION['b']['page3']=$_POST; FETCHING VALUE IN SESSION

$query = "INSERT INTO `a`(`textarea`) values('".$page3['B']."')";
// inserted properly textarea value in database

// now fetching textarea value

$query  = "SELECT * FROM `a` WHERE `id` = '1'";
$data       = mysqli_query($conn,$query);
$result     =mysqli_fetch_array($data,MYSQLI_ASSOC);
$textarea1 = $result['textarea'];

现在想要保留textarea值:

<textarea class="form-control" rows="3" name="texta">
 //CODE FOR RETAINING TEXTAREA VALUE
<?php if(!empty($_SESSION['texta']))echo $_SESSION['texta']; ?>
</textarea>

1 个答案:

答案 0 :(得分:2)

假设,

<强> HTML:

<form action="" method="POST">
..
<textarea class="form-control" name="a" rows="3"> </textarea>
..
</form>

<强> PHP:

<?php

// Setting textarea value in session if not empty
if(!empty($_POST['a']))
{
    $_SESSION['texta'] = $_POST['a'];
}

// Inserting to database
..
..

再次HTML:

<textarea class="form-control" rows="3" name="texta">
<?php 
    if(!empty($_SESSION['texta'])) 
        echo $_SESSION['texta']; 
?>
</textarea>