我对 PHP 很陌生。我有一个页面,我希望用户能够输入引文,然后将该信息传递给一个 php 脚本,该脚本查询数据库,以表单形式返回信息,然后允许用户更新任何字段以那种形式返回。
我有三个问题:
1) 当数据返回时,is 只返回字段中的第一个单词。许多字段包含多个单词。
2)当用户更改字段中的数据时,数据库不会更新。
3)我似乎不知道如何让表单字段像我在数据输入中那样显示。
下面是查询和返回数据的代码,供用户在必要时查看和更新:
<?php
mysql_connect("***************", "*********", "****") or die(mysql_error());
mysql_select_db("***********") or die(mysql_error());
$searchterm= $_POST['searchterm'];
$query = "SELECT Citation, Category, Overview, Facts, Decision, Keywords, Link FROM cases WHERE citation = '$searchterm'";
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result))
{
echo "<form action=".$_SERVER['PHP_SELF']." method=post>" .
"Case Citation: <input type=text name=Citation value={$row['Citation'] }><br>" .
"Category: <input type=text name=Category value={$row['Category'] }><br>" .
"Overview: <input type=text name=Overview value={$row['Overview'] }><br>" .
"Case Facts: <input type=text name=Facts value={$row['Facts'] }><br>" .
"Decision: <input type=text name=decision value={$row['Decision'] }><br>" .
"Keywords: <input type=text name=Keywords value={$row['Keywords'] }><br>" .
"Weblink: <input type=text name=Link value={$row['Link'] }><br>" .
"<input type=submit name=submit value=Update>" .
"</form>";
}
//when they click submit
if (isset($_POST['submit'])) {
$Citation=$_POST['Citation'];
$Category=$_POST['Category'];
$Overview=$_POST['Overview'];
$Facts=$_POST['Facts'];
$Decision=$_POST['Decision'];
$Keywords=$_POST['Keywords'];
$Link=$_POST['Link'];
$update = "UPDATE IGNORE cases SET citation='$citation', category='$category', overview='$overview', facts='$facts', decision='$decision', keywords='$keywords', link='$link' WHERE citation = '%$searchterm%'";
$add = mysql_query($update);
}
?>
这是我用来添加数据的表格:
<form action="process.php" method="post">
Case Citation: <input type="text" name="citation" size=128><br>
Category: <input type="text" name = "category" size=56><br>
Overview: <textarea class="textarea" cols="96" row="8" name = "overview"> </textarea><br>
Case Facts: <textarea class="textarea" cols="96" row="8" name = "facts"></textarea><br>
Decision: <input type="text" name = "decision" size=56><br>
Keywords: <textarea class="textarea" cols="96" row="8" name = "keywords"></textarea><br>
Web Link: <input type="text" name = "link" size=128><br>
<input type="submit" value="Submit">
</form>
这是将信息保存到数据库的代码:
<?
$citation=$_POST['citation'];
$category=$_POST['category'];
$overview=$_POST['overview'];
$facts=$_POST['facts'];
$decision=$_POST['decision'];
$keywords=$_POST['keywords'];
$link=$_POST['link'];
mysql_connect("*************", "************", "*********") or die(mysql_error());
mysql_select_db("************") or die(mysql_error());
mysql_query("INSERT INTO `cases` VALUES ('$citation', '$category', '$overview', '$facts', '$decision', '$keywords', '$link')");
Print "Your information has been successfully added to the database. Add case page will automatically reload.";
?>