php mysql pasing as parameter textarea多行

5t7ly7z5  于 2021-06-24  发布在  Mysql
关注(0)|答案(1)|浏览(349)




我有一个问题,通过一个textarea到另一个网页时,包含多行。
我有3页:
1.-\u testinserttext.php=在数据库中插入新文本
2.-\u testshowtext.php=从数据库中选择文本并重定向到修改页面
3.-\u testtextmodify.php=更新由\u testshowtext.php传递的文本
我的数据库表中的结构:

CREATE TABLE `tblTest`
(
   `clmSerie`    int     (11) NOT NULL
  ,`clmTextArea` text         NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

如果我通过\u testinserttext.php插入一个有两行的文本,我就能够通过\u testshowtext.php正确显示
我的问题是(通过href)将那些包含多行的记录重定向到\u testtextmodify.php页面(因为只有一行可以正常工作)。它不是重定向。
你能帮帮我吗?
我的代码可以在下面找到:
1.-\u 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.-\u 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.-\u 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>
wf82jlnq

wf82jlnq1#

感谢sloan thrasher的评论,我修改了\u testtextmodify.php和\u testshowtext.php,现在我将内容传递到一个隐藏的文本区域,而不是将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>

相关问题