У меня возникла проблема передать текстовое поле на другую страницу, когда содержит несколько строк.
У меня 3 страницы:
1. -_testInsertText.php = INSERT новый текст в базе данных
2. -_testShowText.php = ВЫБРАТЬ тексты из базы данных и перенаправить на страницу модификации
3. -_testTextModify.php = ОБНОВИТЬ текст, переданный _testShowText.php
Моя структура из моей таблицы из базы данных:
CREATE TABLE 'tblTest'
(
'clmSerie' int (11) NOT NULL
,'clmTextArea' text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Если я вставляю текст с двумя строками через _testInsertText.php, я могу правильно отобразить его через _testShowText.php
Моя проблема заключается в перенаправлении (через href) этих записей с более чем одной строкой на страницу _testTextModify.php (для 1 строки работает нормально). Это не перенаправление.
Не могли бы вы мне помочь?
Мой код можно найти ниже:
1. -_testInsertText.php
<?php
$txtEvolucion = '';
if(isset($_POST['Insert']) && isset($_POST["txtEvolucion"]))
{
$txtEvolucion = $_POST["txtEvolucion"];
require_once('mysqli_connect.php');
echo "<br>". "txtEvolucion={" . $txtEvolucion ."}";
$query = "INSERT INTO tblTest (clmTextArea) VALUES (?)";
$stmt = mysqli_prepare($dbc, $query);
mysqli_stmt_bind_param($stmt, "s", $txtEvolucion);
mysqli_stmt_execute($stmt);
$affected_rows = mysqli_stmt_affected_rows($stmt);
echo $affected_rows;
if($affected_rows == 1)
{
$txtEvolucion = '';
echo "Inserted";
mysqli_stmt_close($stmt);
}
else
{
ini_set('display_errors', 'On');
mysqli_stmt_close($stmt);
}
}
?>
<html>
<head>
<title>Insert TextArea</title>
</head>
<body>
<h1>Insert TextArea</h1>
<div id="divAgenda">
<form id="contact" action="" method="post">
<fieldset>
<textarea id="txtEvolucion" name="txtEvolucion" tabindex="4" cols="90" rows="7"
value="<?= $txtEvolucion ?> "
><?= $txtEvolucion ?></textarea><br><br>
<button name="Insert" type="submit" id="contact-submit" data-submit="...Sending">Insert</button><br>
</fieldset>
</form>
</body>
</html>
2. -_testShowText.php
<?php
$output = '';
require_once('mysqli_connect.php');
$query = mysqli_query($dbc,"SELECT clmSerie
,clmTextArea
FROM tblTest
"
) or die('Error to select!: {' . mysqli_error($dbc) . '}');
$count = mysqli_num_rows($query);
$output .= '<table border="1" align="left" cellspacing="5" cellpadding="8">
<tr><td align="left"><b>MODIFY </b></td>
<td align="left"><b>Id </b></td>
<td align="left"><b>Text Area </b></td>
</tr>';
while($row = mysqli_fetch_array($query))
{
$serie = $row['clmSerie'];
$descripcion = utf8_encode($row['clmTextArea']);
$descripcion = nl2br($descripcion);
$output .= '<tr><td align="left"><a href="_testTextModify.php?descripcion=' . $descripcion .
'&serie=' . $serie .
'">Modify
</a></td>
<td align="left">' .$serie . '</td>
<td align="left">' .$descripcion . '</td>
';
$output .= '</tr>';
}
?>
<html>
<head>
<title>Show TextArea</title>
</head>
<body>
<h1>Show TextArea</h1>
<?php echo $output;?>
</body>
</html>
3. -_testTextModify.php
<?php
$txtEvolucion = '';
$txtEvolucionOld = $_GET['descripcion'];
$idSerie = $_GET['serie'];
echo "<br>". "txtEvolucionOld={" . $txtEvolucionOld ."}";
if(isset($_POST['Modify']) && isset($_POST["txtEvolucion"]))
{
$txtEvolucion = $_POST["txtEvolucion"];
require_once('mysqli_connect.php');
echo "<br>". "txtEvolucion={" . $txtEvolucion ."}";
$query = "UPDATE tblTest
SET clmTextArea = ?
WHERE clmTextArea = ?
AND clmSerie = ?
";
$stmt = mysqli_prepare($dbc, $query);
mysqli_stmt_bind_param($stmt, "sss", $txtEvolucion, $txtEvolucionOld, $idSerie);
mysqli_stmt_execute($stmt);
$affected_rows = mysqli_stmt_affected_rows($stmt);
echo $affected_rows;
if($affected_rows == 1)
{
$txtEvolucion = '';
echo "Modified";
mysqli_stmt_close($stmt);
}
else
{
ini_set('display_errors', 'On');
mysqli_stmt_close($stmt);
}
}
?>
<html>
<head>
<title>Modify TextArea</title>
</head>
<body>
<h1>Modify TextArea</h1>
<div id="divAgenda">
<form id="contact" action="" method="post">
<fieldset>
<textarea id="txtEvolucion" name="txtEvolucion" tabindex="4" cols="90" rows="7"
value="<?= $txtEvolucion ?> "
><?= $txtEvolucionOld ?></textarea><br><br>
<button name="Modify" type="submit" id="contact-submit" data-submit="...Sending">Modify</button><br>
</fieldset>
</form>
</body>
</html>
Благодаря комментарию Sloan Thrasher, я изменил _testTextModify.php и _testShowText.php. И теперь я передаю содержимое скрытой TextArea вместо href на страницу модификации, и теперь она отлично работает, когда она поставляется с несколькими строками.
Всем спасибо :)
Новый код:
_testTextModify.php
<?php
if(isset($_POST['fromTestShowText']))
{
$txtEvolucionOld = $_POST['descripcion'];
$idSerie = $_POST['serie'];
}
if(isset($_POST['Modify']) && isset($_POST["txtEvolucionOld"]))
{
$txtEvolucionOld = $_POST["txtEvolucionOld"];
require_once('mysqli_connect.php');
$query = "UPDATE tblTest
SET clmTextArea = ?
WHERE clmSerie = ?
";
$stmt = mysqli_prepare($dbc, $query);
mysqli_stmt_bind_param($stmt, "ss", $_POST['txtEvolucionOld'], $_POST['idSerie']);
mysqli_stmt_execute($stmt);
$affected_rows = mysqli_stmt_affected_rows($stmt);
echo "<br>". "affected_rows={" . $affected_rows ."}";
if($affected_rows == 1)
{
$txtEvolucionOld = $recibeSerieEvolucion = '';
echo "Modified";
mysqli_stmt_close($stmt);
}
else
{
ini_set('display_errors', 'On');
mysqli_stmt_close($stmt);
}
}
?>
<html>
<head>
<title>Modify TextArea</title>
</head>
<body>
<br><a href="_testShowText.php">Show</a>
<br><a href="_testInsertText.php">Insert</a>
<h1>Modify TextArea</h1>
<div id="divAgenda">
<form id="contact" action="" method="post">
<fieldset>
<input type="hidden" readonly id="idSerie" name="idSerie" size="2" type="text" maxlength="100" tabindex="3"
value="<?= $idSerie ?>"
><br>
<textarea id="txtEvolucionOld" name="txtEvolucionOld" tabindex="4" cols="90" rows="7"
value="<?= $txtEvolucionOld ?> "
><?= $txtEvolucionOld ?></textarea><br><br>
<button name="Modify" type="submit" id="contact-submit" data-submit="...Sending">Modify</button><br>
</fieldset>
</form>
</body>
</html>
_testShowText.php
<?php
$output = '';
require_once('mysqli_connect.php');
$query = mysqli_query($dbc,"SELECT clmSerie
,clmTextArea
FROM tblTest
"
) or die('Error to select!: {' . mysqli_error($dbc) . '}');
$count = mysqli_num_rows($query);
$output .= '<table border="1" align="left" cellspacing="5" cellpadding="8">
<tr><td align="left"><b>MODIFY </b></td>
<td align="left"><b>Id </b></td>
<td align="left"><b>Text Area </b></td>
</tr>';
while($row = mysqli_fetch_array($query))
{
$serie = $row['clmSerie'];
$descripcion = utf8_encode($row['clmTextArea']);
//$descripcion = nl2br($descripcion);
$output .= '<tr><td align="left"><form action="_testTextModify.php" method="post">
<button name = "fromTestShowText" type="image"
value="Submit">Modify
</button>
</td>
<td align="left">' .$serie . '</td>
<td align="left"><input hidden readonly id="serie" name="serie" type="text"
value="'. $serie . '"
>
<textarea id="descripcion" name="descripcion" cols="50" rows="6"
value = "'.$descripcion.'"
readonly>'. $descripcion .'</textarea>
</td>
</form>';
$output .= '</tr>';
}
?>
<html>
<head>
<title>Show TextArea</title>
</head>
<body>
<br><a href="_testShowText.php">Show</a>
<br><a href="_testInsertText.php">Insert</a>
<h1>Show TextArea</h1>
<?php echo $output;?>
</body>
</html>
urlencode()
для переменных в href.