多页后ECHO结果变成FORM

ECHO Results into a FORM after multiple pages

我在下一页看到了关于做这种事情的教程,将结果直接从表单回显到不同的表单,但是我面临的问题略有不同,我找不到任何涵盖它的线程,我相信有人会通过回答这个来证明我是多少新手。

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

<!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 页面的 table 中,代码如下所示: enter code here

  } 
 }
}  
?>
 <!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>

我在最后有一个 link 可以带你到 Manageclient.php,用户会 select Manage Client 在 Search.php 显示结果的页面。然后,这会将用户带到 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>

我收到以下错误消息:

注意:未定义的变量:结果在第 105 行的 C:\xampp\htdocs\acaproject\manageclient.php

警告:mysql_fetch_array() 期望参数 1 为资源,在第 105

行的 C:\xampp\htdocs\acaproject\manageclient.php 中给定为空


注意事项:未定义索引:C中的ClientID:\xampp\htdocs\acaproject\manageclient.php线上 75


通知: 未定义索引: C:\xampp\htdocs\acaproject\manageclient.php 中的名字线上 81


通知:未定义索引:C中的姓氏:\xampp\htdocs\acaproject\manageclient.php线上 86

进一步编辑:在 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>