我在下面的页面上看到了关于做这类事情的教程,将结果直接从表单中回声到不同的表单中。然而,我面临的问题略有不同,我找不到任何涵盖它的线程,我相信有人会通过回答这个问题来证明我是一个多么新手。
我有一个搜索表单,如下所示:
<!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页面的表格中,代码显示在此处: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>
我在末尾有一个链接,可以将您带到Manageclient.php,用户会在显示结果的Search.php页面上选择Manage Client。这将使用Search.php的结果中的预填充表单将用户带到Manageclient.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:''examplep''htdocs''acaproject''manageclient.php中的结果
警告:mysql_fetch_array()要求参数1为resource,在第105行的C:''examplep''htdocs''acaproject''manageclient.php中给定null
注意:未定义的索引:C:''examplep''htdocs''acaproject''manageclient.php中的ClientID第75行
注意:未定义的索引:C:''examplep''htdocs''acaproject''manageclient.php中的forename81行
注意:未定义的索引:C:''examplep''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>