2015-02-09 87 views
1

問題是我無法保留textarea的值回到第 從數據庫獲取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 class="form-control" rows="3" name="texta"> 
//CODE FOR RETAINING TEXTAREA VALUE 
<?php if(!empty($_SESSION['texta']))echo $_SESSION['texta']; ?> 
</textarea> 
+1

我不知道你在哪裏設置'$ _SESSION [」 TEXTA']'。你確定它包含你認爲它包含的內容嗎? – 2015-02-09 08:17:23

回答

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> 
+0

thankz很多.... – user 2015-02-09 09:09:37

+0

如何取消設置此會話時,數據庫條目不存在,我想再次空白形式? – user 2015-02-09 09:37:49