php - 多页后ECHO结果变成FORM

标签 php mysql forms search edit

我已经看到有关执行此类操作的教程,将结果直接从表单回显到下一页的不同表单中,但是我面临的问题略有不同,我找不到任何线程掩盖它,我相信有人会通过回答这个问题来证明我是多么的新手。

我有一个搜索表单,如下所示:

<!DOCTYPE  HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"          "http://www.w3.org/TR/html4/loose.dtd"> 
 <html> 
  <head> 
    <meta  http-equiv="Content-Type" content="text/html;  charset=iso-8859-1"> 
    <title>Search  Contacts</title> 
  </head> 
  <p><body> 
    <h3>Search  Contacts Details</h3> 
    <p>You  may search either by first or last name</p> 
    <form  method="post" action="search.php?go"  id="client"> 
      <input  type="text" name="name"> 
  <input  type="submit" name="submit" value="Search"> 
</form> 
</body> 
</html> 
</p> 

然后结果显示在 Search.PHP 页面的表格中,代码如下所示: 在这里输入代码

  } 
 }
}  
?>
 <!DOCTYPE HTML>
 <html>
 <head>
 <title>Client/title>
 <link href="/csstwo.css" type="text/css" rel="stylesheet">
 </head>
<div id="Header">
<h1>Search results</h1>
<div id="Banner"></div>
<div id="logo"></div>
<div style="clear:  both;"></div>
</div> <!-- /Header -->

<body>
    <div id="nav">
    <div id="nav_wrapper">
        <ul>
            <li><a href="index.php">Home</a></li>   
            <li><a href="">Client</a>
                <ul>
                    <li><a href="client.php">Add a Client</a></li>
                    <li><a href="#">Manage Client</a></li>
                    </li><li><a href="#">Client List</a></li>
                </ul>   
            <li><a href="">Case</a>
                <ul>
                    <li><a href="case.php">Add a Case</a></li>
                    </li><li><a href="caselist.php">Manage Case</a></li>
                </ul>   
            <li><a href=#">Help <img src="arrow.jpg"></a>
                <ul>
                    <li><a href="#">Case</a></li>
                    <li><a href="#">Client</a></li>
                    </li><li><a href="#">Contacts</a></li>
                </ul>
            </li>
        </ul>
    </div>
 </div>
<div id="content">  

  <table width="70%" cellpadding="5" cellspace="5" position="centre">
<tr>
    <td><strong>ID</strong></td>
    <td><strong>Forename</strong></td>
    <td><strong>Surname</strong></td>
    <td><strong>Postcode</strong></td>
    <td><strong>Address Line One</strong></td>
    <td><strong>Address Line Two</strong></td>
    <td><strong>Town/City</strong></td>
    <td><strong>Contact Number</strong></td>
    <td><strong>Manage Client</strong></td>
</tr>
 <?php while ($row =mysql_fetch_array($result)) { ?>
    <tr>
        <td><?php echo $ID =$row ['ClientID'] ?></td>
        <td><?php echo $FirstName =$row ['forename'] ?></td>
        <td><?php echo $LastName =$row ['surname'] ?></td>
        <td><?php echo $row ['postcode'] ?></td>
        <td><?php echo $row ['addresslineone'] ?></td>
        <td><?php echo $row ['addresslinetwo'] ?></td>
        <td><?php echo $row ['towncity'] ?></td>
        <td><?php echo $row ['contactnumber'] ?></td>
        <td><a href='manageclient.php?id={$row['id']}'>Manage</a></td>
    </tr>
  <?php } ?>
  </table>
  </body>

我在末尾有一个链接,可以将您带到 Manageclient.php,用户可以在显示结果的 Search.php 页面上选择 Manage Client。然后,这会将用户带到 Manageclient.php,其中包含来自 Search.php 结果的预填充表单。

我可能非常愚蠢,但我似乎无法携带 Search.php 的结果并将它们回显到 Manageclient.php 上的表单中,我总是不断收到错误消息,说变量未定义。

我希望这是有道理的,我们将不胜感激任何对此的帮助。

编辑:

我在 manageclient.php 上发布到这个表单:

<form action="manageclient.php" method="post" form id="client">
 <div class="label">
  <h1> Edit a Client
 <span>Please enter the case's details below.</span>
 </h1>
<div class="label">*ClientID:
    <div class="txtbox">
        <input name="ClientID" type="text" id="txt" placeholder="Enter Your First Name." value="<?php echo $result ['ClientID']; ?>"/>
    </div>  
</div>
<br>
<div class="label">*Forename:
    <div class="txtbox">
        <input name="forename" type="text" id="txt" placeholder="Enter Your Last Name." value="<?php echo $result ['forename']; ?>"/>
</div>
</div>
    <div class="label">*Surname:
    <div class="txtbox">
        <input name="surname" type="text" id="txt" placeholder="DD/MM/YYYY." value="<?php echo $result ['surname']; ?>"/>
</div>
</div>

我收到以下错误消息:

注意: undefined variable :结果在第105行C:\xampp\htdocs\acaproject\manageclient.php

警告:mysql_fetch_array() 期望参数 1 为资源,第 105 行 C:\xampp\htdocs\acaproject\manageclient.php 中给出的 null


注意:75C:\xampp\htdocs\acaproject\manageclient.php中未定义索引:ClientID


注意: undefined index :C:\xampp\htdocs\acaproject\manageclient.php81 中的名字


注意:未定义索引:C:\xampp\htdocs\acaproject\manageclient.php86 中的姓氏

进一步编辑:在 search.php 中显示 PHP

<?php 
if(isset($_POST['submit'])){ 
if(isset($_GET['go'])){ 
  if(preg_match("/^[  a-zA-Z]+/", $_POST['name'])){ 
  $name=$_POST['name']; 
  //connect  to the database 
  $db=mysql_connect  ("localhost", "root",  "password") or die ('I cannot connect to the database  because: ' . mysql_error()); 
  //-select  the database to use 
  $mydb=mysql_select_db("acatestdb"); 
  //-query  the database table 
  $sql="SELECT  ClientID, forename, surname, dateofbirth, postcode, addresslineone, addresslinetwo, towncity, contactnumber FROM clienttbl WHERE surname LIKE '%" . $name .  "%' OR forename LIKE '%" . $name ."%'"; 
  //-run  the query against the mysql query function 
  $result=mysql_query($sql); 
  //-create  while loop and loop through result set 

  } 
}


?>

最佳答案

我不确定你在问什么。

你的风格和代码一样非常不清楚:-(

但是检查这一行:

<td><a href='manageclient.php?id={$row['id']}'>Manage</a></td>

应该是

<td><a href="manageclient.php?id=<?=$row['id'] ?>&ClientID=<?=$row['ClientID'] ?>&forename="<?=urlencode($row ['forename']) ?>&surname="<?=urlencode($row['surname']) ?>">Manage</a></td>

在您的 manageclient.php 中您可以尝试:

<div class="label">*ClientID:
    <div class="txtbox">
        <input name="ClientID" type="text" id="txt" placeholder="Enter Your First Name." value="<?=(isset($_GET['ClientID']))?$_GET['ClientID']:'' ?>"/>
    </div>  
</div>
<br>
<div class="label">*Forename:
    <div class="txtbox">
        <input name="forename" type="text" id="txt" placeholder="Enter Your Last Name." value="<?=(isset($_GET['forename']))?$_GET['forename']:'' ?>"/>
</div>
</div>
    <div class="label">*Surname:
    <div class="txtbox">
        <input name="surname" type="text" id="txt" placeholder="DD/MM/YYYY." value="<?=(isset($_GET['surname']))?$_GET['surname']:'' ?>"/>
</div>

关于php - 多页后ECHO结果变成FORM,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28816510/

相关文章:

javascript - 通过选择从开始日期算起的周数或月数来自动结束日期

php - 插入数据库错误SQLSTATE[HY093]

php - Mysql SELECT from T1 WHERE ID T2 中不存在于 T3 中

php - Yii 关系中的关系和连接表属性

javascript - 如何使用 jQuery 对注入(inject)的 ajax 表单进行多次验证?

php订单价格更新

php - 在 PHP 中将 URL 参数解析为变量的最快方法

带有 IN 子句和 LIMIT 的 PHP PDO

php - 使用 PDO 类将 MySql 表数据选择到数组中?

Django:在模型选择中结合使用惰性翻译和标记安全