我有一个php语句,它使用各种sql查询将数据输入到两个不同的表中。第一个查询工作正常,但一旦我越过
if (isset($origin, $destination));
指出,虽然脚本在底部重定向,但它没有任何作用,就好像它完成一样。
对于出现问题的任何帮助都将不胜感激。
$sql="INSERT INTO journey_boards (headline, text, tag, origin, destination, userid)
VALUES
('$_POST[posttitle]', '$_POST[posttext]', '$_POST[tag]', '$_POST[origin]', '$_POST[destination]', '$_SESSION[id]')";
$origin = $_POST[origin];
$destination = $_POST[destination];
if (isset($origin, $destination)) {
$query = mysqli_query($con, "SELECT * FROM journey_ranking WHERE origin = $origin AND destination = $destination");
}
$count = mysql_num_rows($query);
if ($count = 1) {
$sql2 = "UPDATE journey_ranking SET rank = rank + 1 WHERE origin = $origin AND destination = $destination";
} else {
$sql3 = "INSERT INTO journey_ranking (origin, destination, rank)
VALUES
('$_POST[origin]', '$_POST[destination]', 1)";
}
if (!mysqli_query($con,$sql))
{
die('Error: ' . mysqli_error($con));
}
header('location: journeys.php');
mysqli_close($con);
答案 0 :(得分:0)
另外,改变
if (isset($origin, $destination)) {
$query = mysqli_query($con, "SELECT * FROM journey_ranking WHERE origin = $origin AND destination = $destination");
}
$count = mysql_num_rows($query);
到
if (isset($origin, $destination)) {
$query = mysqli_query($con, "SELECT * FROM journey_ranking WHERE origin = $origin AND destination = $destination");
$count = mysql_num_rows($query);
} else $count = 0;
和
if ($count = 1) {
应该是
if ($count == 1) {