不要在php中清除文本框值

时间:2016-06-21 06:06:52

标签: php

我正在尝试从上一个表单中获取所选ID,并将id插入另一个数据库。从表单中插入数据后,不应清除ID,而可以清除其他详细信息。

以下是必须插入ID的表单的屏幕截图 Screeshot 当用户单击添加图像特定ID时,单击添加图像将以另一种形式发布。

提交表格后,不应清除ID。而其他文本框可以清除。

这是代码

    $query2 = "SELECT * FROM abc";
    $result2=mysql_query($query2) or die("Query Failed : ".mysql_error());
    if(isset($_POST['submit']))
    {
    $id= $_POST['id'];

    if( ! ctype_alnum($id) )
      die('invalid id');

   $query = "SELECT id FROM `abc` WHERE `id` =$id";
   $run = mysql_query($query);
    if(mysql_num_rows($run)>0){
    echo "<script>window.open('addimg.php?id=".$id."','_self')</script>";
    }

    else {

        echo "<script>alert('No is Invalid!')</script>";
        }
    }
    ?>
    <table width='300' align='center' border='1' cellpadding="5px" cellspacing="0px" style="color:#494949;font-size:12px;  font-family:Cambria;">
    <tr>
    <td>ID</td>
    <td>URl Small Image</td>
    <td>URL Large Image</td>

    <td>Add Image</td></tr>
    <?php
    while($row=mysql_fetch_array($result2))
    {?>

   <form method="post" action="report.php">


    <tr><td>
        <input type="text" name="id" class="input" size="20" value="<?php echo $row['id']; ?>" readonly></td>
    <td>
        <input type="text" name="s_img" class="input" size="20" value="<?php echo $row['s_img']; ?>" readonly></td> 
        <td>
    <input type="text" name="l_img"  class="input" size="20" value="<?php echo $row['l_img']; ?>" readonly></td>


    <td> <input type="submit" name="submit" value="ADD IMAGE" class="button" /></td>
     </form>
    <?php
    }
    ?>

Addimg.php

<form name="XIForm" id="XIForm" method="POST" action="addimg.php">
 <h1>News Description</h1> 

  <p> 
 <label for="News_id" class="uname"> News_ID</label>
<input type="text" id="news_id" name="news_id"  type="text" value="<?php if(isset($_GET['id'])) { echo $_GET['id']; } ?>" readonly> <br />
                                </p>

 <label for="img1" class="uname"> Img1</label>
          <input type="text" id="img1" name="img1"  type="text"/> <br />
           </p>

PHP代码

     if(isset($_POST['XIsubmit'])) {


$news_id  = $_POST["news_id"];

    $img1  = $_POST["img1"];

    if($img1!="")
    {
    $query=("INSERT INTO images (news_id,img)VALUES('$news_id','$img1')") or die(mysql_error());  
 $retval = mysql_query( $query, $dbhandle );
 echo ""
      if(! $retval ) {
      die('Could not enter data: ' . mysql_error());


   }
    }
    }
 ?> 

0 个答案:

没有答案