如何通过 PHP 上的 if else 语句更改表单操作?
How to change form action thru if else statement on PHP?
如何通过将重定向到其他 PHP 页面的 if else 语句更改表单操作?
我是 PHP 的新手,提前谢谢大家
这是我的代码:
<?php
if(isset($_POST['btn_submit']))
{
$Fname = $_POST['Fname'];
$Lname = $_POST['Lname'];
$sel = "SELECT Lname FROM users WHERE Fname='" . $Fname . "'";
$result = $conn->query($sel);
if($result->num_rows>0)
{
while($row = $result->fetch_assoc())
{
$Lname = $row['Lname'];
}
if ($Lname == $Lname)
{
echo "Correct data!";
/*i want to put redirect page here*/
}
else
{
echo "invalid Firsname!";
}
}
else
{
echo "invalid Lastname!";
}
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="text" name="Fname" placeholder="Enter your Fname" required>
<input type="text" name="Lname" placeholder="Lname" required>
<input type="submit" name="btn_submit" value="Sign In">
</form>
例子
if ($_POST['p'] == 1) { $insertGoTo = "t1.php"; }
if ($_POST['p'] == 2) { $insertGoTo = "t2.php"; }
header(sprintf("Location: %s", $insertGoTo));
?
如何通过将重定向到其他 PHP 页面的 if else 语句更改表单操作? 我是 PHP 的新手,提前谢谢大家
这是我的代码:
<?php
if(isset($_POST['btn_submit']))
{
$Fname = $_POST['Fname'];
$Lname = $_POST['Lname'];
$sel = "SELECT Lname FROM users WHERE Fname='" . $Fname . "'";
$result = $conn->query($sel);
if($result->num_rows>0)
{
while($row = $result->fetch_assoc())
{
$Lname = $row['Lname'];
}
if ($Lname == $Lname)
{
echo "Correct data!";
/*i want to put redirect page here*/
}
else
{
echo "invalid Firsname!";
}
}
else
{
echo "invalid Lastname!";
}
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
<input type="text" name="Fname" placeholder="Enter your Fname" required>
<input type="text" name="Lname" placeholder="Lname" required>
<input type="submit" name="btn_submit" value="Sign In">
</form>
例子
if ($_POST['p'] == 1) { $insertGoTo = "t1.php"; }
if ($_POST['p'] == 2) { $insertGoTo = "t2.php"; }
header(sprintf("Location: %s", $insertGoTo));
?