我已经看过关于做这类事情的教程,将结果直接从表单反映到下一页的不同表格中,但我面临的问题略有不同,我可以&找不到涵盖它的任何主题,我确定有人会通过回答这个来证明我是多少新手。
我有一个搜索表单,如下所示:
<!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:\ xampp \ htdocs \ acaproject \ manageclient.php
警告:mysql_fetch_array()要求参数1为资源,在第105行的C:\ xampp \ htdocs \ acaproject \ manageclient.php中给出null
注意:未定义的索引: C:\ xampp \ htdocs \ acaproject \ manageclient.php 中的ClientID 75
注意:未定义的索引: C:\ xampp \ htdocs \ acaproject \ manageclient.php 中的forename 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
}
}
}
?&GT;
答案 0 :(得分:0)
我不确定你要求的是什么。
你的风格与代码一样非常不清楚: - (
但请查看以下一行:
<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>