你可以使用header
:
header("Location: /full_loan_details.php?id=$res[id]");
如前所述脚本很容易受到注入攻击。您应该使用PDO's
:
<?php
define("DB_DSN", "mysql:host=localhost;dbname=foo");
define("DB_USERNAME", "root");
define("DB_PASSWORD", "password");
// define sql
$sSQL = "UPDATE loan SET loana=:loana, dater=:dater, apaid=:apaid WHERE id=:id";
// create an instance of the connection
$conn = new PDO(DB_DSN, DB_USERNAME, DB_PASSWORD);
// prepare
$st = $conn->prepare($sSQL);
// securely bind any user input in the query
$st->bindValue(":loana", $loana, PDO::PARAM_STR);
$st->bindValue(":dater", $dater, PDO::PARAM_STR);
$st->bindValue(":apaid", $apaid, PDO::PARAM_STR);
$st->bindValue(":id", $id, PDO::PARAM_INT);
// execute the connection
if($st->execute()){
header("Location: /full_loan_details.php?id=".$id);
}else{
// didnt execute
}
你可以做一个SELECT
确认更改和或得到一个值。与上述方法相同,但需要以下内容来读取它;
要提取单列使用If
,或者如果多于1行使用while
if($row = $st->fetch()){
header("Location: /full_loan_details.php?id=".$row['id']);
}
注意:这可能是不安全的用户重定向到基于从DB unsanatised数据的位置。即使你已经用上面的方法插入它。确保您正确地清洁所有输出。
您可以使用['header'](http://php.net/manual/en/function.header.php)将用户重定向到页面。 – secelite
在更新记录的同一动作中,您可以在更新后立即运行选择查询。 – Loko
***请[停止使用'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- statement.php),并考虑使用PDO,[这真的很简单](http://jayblanchard.net/demystifying_php_pdo.html)。 –