How do I change a string line submitted in the form with another form input

一笑奈何 提交于 2020-02-08 07:46:07

问题


In my first page I have this code:

$number="1234567891";
$str="456";

echo "<form action='edit.php' method='POST'><input type='hidden' name='msg' value='$message' />
        <input type='hidden' name='text' value='$number' />
        <input type='hidden' name='edit' value='$str' />
        <input type='submit' name='chedit' value='Go' style='position:relative; top:25px; left: 50%;'>
      </form>";

In my edit.php I have this code:

<form action="#" method="POST">
   Edit Number
   <input type="text" name="change" value="$mumu"/>
   <input type="submit" name="pch" value="Change"/>
</form>

<?php
       if (isset($_POST["chedit"]))
       {
           $suj = $_POST["msg"];
           $text = $_POST["text"];
           $mumu =$_POST["edit"];
           if(isset($_POST["pch"]))
           {
               $change = $_POST["change"];       
               $obinna = str_replace("$change","$mumu","$text"); 
               echo $obinna;
           }
       }

     ?> 

My problem is that whenever I put a new text in new form and click submit to edit a character in the old string submitted line the page refreshes and no result is output. Please can anybody sort this out?


回答1:


// try this ..

    if (isset($_POST["chedit"]))
       {
           $suj = $_POST["msg"];
           $text = $_POST["text"];
           $mumu =$_POST["edit"];
           if(isset($_POST["pch"]))
           {
               $change = $_POST["change"];   
                          //456 ,   //555(post value) , //(your text)12345678910
// $obinna = str_replace("Set old value you change in text","set new value you want to set in text ","your orignal text "); 
               $obinna = str_replace("$mumu","$change","$text"); 
               echo $obinna;
           }
       }
       echo '<form action="#" method="POST">
          Edit Number
          <input type="text" name="change" value="" placeholder="Change"/>
          <input type="text" name="edit" value="" placeholder="Edit"/>  
          <input type="submit" name="pch" value="Submit"/>
       </form>'

Check Demo Url :- https://eval.in/931366



来源:https://stackoverflow.com/questions/48121867/how-do-i-change-a-string-line-submitted-in-the-form-with-another-form-input

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!