好吧……我知道我已经快要让它发挥作用了……但事实并非如此……
我使用二维码通过 URL 传递变量......到“secure.php”页面
secure.php 是简单的密码保护......当用户输入正确的密码时,我希望页面将变量从 url 传递到数据库......这是我的代码
> <?php
// Prepare variables for database connection
$dbusername = "username"; // enter database username
$dbpassword = "password"; // enter database password
$server = "0.0.0.0";
$db = "mydatabase";
// Connect to your database
//$mysqli = mysqli_connect($server,$dbusername,$dbpassword,$db) or die("Error " . mysqli_error($mysqli));
//$FN = $_GET['FirstName'];
//$LN = $_GET['LastName'];
//$DL = $_GET['DLNumber'];
//$date = date('Y-m-d');
$user = $_POST['user'];
$pass = $_POST['pass'];
if($user == "user"
&& $pass == "pass")
{
if (!empty($_GET))
$mysqli = mysqli_connect($server,$dbusername,$dbpassword,$db) or die("Error " . mysqli_error($mysqli));
$FN = $_GET['FirstName'];
$LN = $_GET['LastName'];
$DL = $_GET['DLNumber'];
$date = date('Y-m-d');
//$sql = "INSERT INTO attendance(FirstName,LastName,DLNumber,Date) VALUES ('$FN','$LN', '$DL','$date')";
$sql = "INSERT INTO attendance(FirstName) VALUES ('$FN')";
mysqli_query($mysqli, $sql);
header("Location: http://www.mywebpage.com/");
exit;
}
else
{
if(isset($_POST))
{?>
<form method="POST" action="secure.php">
User <input type="text" name="user"></input><br/>
Pass <input type="password" name="pass"></input><br/>
<input type="submit" name="submit" value="Go"></input>
</form>
<?}
}
Can someone point me in the right direction?
您应该添加查询字符串(
<?=$_SERVER['QUERY_STRING']?>
)来发布网址,因此代码如下:
<?php
// Prepare variables for database connection
$dbusername = "username"; // enter database username
$dbpassword = "password"; // enter database password
$server = "0.0.0.0";
$db = "mydatabase";
// Connect to your database
//$mysqli = mysqli_connect($server,$dbusername,$dbpassword,$db) or die("Error " . mysqli_error($mysqli));
//$FN = $_GET['FirstName'];
//$LN = $_GET['LastName'];
//$DL = $_GET['DLNumber'];
//$date = date('Y-m-d');
$user = $_POST['user'];
$pass = $_POST['pass'];
if($user == "user"
&& $pass == "pass")
{
if (!empty($_GET))
$mysqli = mysqli_connect($server,$dbusername,$dbpassword,$db) or die("Error " . mysqli_error($mysqli));
$FN = $_GET['FirstName'];
$LN = $_GET['LastName'];
$DL = $_GET['DLNumber'];
$date = date('Y-m-d');
//$sql = "INSERT INTO attendance(FirstName,LastName,DLNumber,Date) VALUES ('$FN','$LN', '$DL','$date')";
$sql = "INSERT INTO attendance(FirstName) VALUES ('$FN')";
mysqli_query($mysqli, $sql);
header("Location: http://www.mywebpage.com/");
exit;
}
else
{
if(isset($_POST))
{?>
<form method="POST" action="secure.php<?=$_SERVER['QUERY_STRING']?>">
User <input type="text" name="user"></input><br/>
Pass <input type="password" name="pass"></input><br/>
<input type="submit" name="submit" value="Go"></input>
</form>
<?php }
}
?>