1
我有两个.php页面,其中一个返回表格的内容,包括每个条目的id以及一个html文本输入,另一个检索细节并允许我更新记录。设置php获取设置变量超链接
我想通过点击列表项目使用href而不是不得不文本输入id和提交存储条目的id。
choose.php
echo "<ul>";
while ($row=mysql_fetch_array($result)) {
$reference=$row[reference];
$name=$row[name];
echo "<li>$reference, $name</li>";
}
echo "</ul>";
session_start();
$_SESSION['regName'] = $reference;
mysql_close($link);
?>
<form method="get" action="update.php">
<input type="text" name="regName" value="">
<input type="submit">
</form>
update.php
session_start();
$reference = $_GET['regName'];
echo "Your selection id is: ".$reference.".";
$query="SELECT * FROM firsttable WHERE reference='$reference'";
$result=mysql_query($query) or die("Query to get data from firsttable failed with this error: ".mysql_error());
$row=mysql_fetch_array($result);
$name=$row[name];
echo "<form method=\"POST\" action=\"updated.php\">";
echo "<p>";
echo "<label for=\"name\">Name: </label><input type=\"text\" id=\"name\" name=\"name\" size=\"30\" value=\"$name\"/>";
echo "<p><input type=\"submit\"></p>";
echo "</form>";
我道歉,如果这似乎很明显,我才开始学习PHP截至今日,它的很多比什么更复杂到现在我已经完成了。
感谢 詹姆斯
***请[停止使用'mysql_ *'函数](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php)。*** [这些扩展名](http://php.net/manual/en/migration70.removed-exts-sapis.php)已在PHP 7中删除。了解[prepared](http://en.wikipedia.org/wiki/Prepared_statement)语句[PDO](http://php.net/manual/en/pdo.prepared-statements.php)和[MySQLi](http://php.net/manual/en/mysqli.quickstart。 prepared-statements.php)并考虑使用PDO,[这真的很简单](http://jayblanchard.net/demystifying_php_pdo.html)。 –
[Little Bobby](http://bobby-tables.com/)说*** [你的脚本存在SQL注入攻击风险。](http://stackoverflow.com/questions/60174/how-can- I-防止-SQL注入式-PHP)***。即使[转义字符串](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string)是不安全的! –
应该很容易;你尝试了什么? –