我正在尝试将参数传递给 php 函数。但是什么都没有发生,我的意思是代码没有将 index.php 中的参数传递给 newPHPClass.php 并且可以在表单操作中调用函数吗?这是我的代码。
索引.php
<?php include '../con_db/connect.php'; ?>
<?php include '../class/newPHPClass.php'; ?>
<form action="index.php" method="post">
<label>Username:</label><input type="text" name="username"/><br/>
<label>Password:</label><input type="text" name="password"/><br/>
<input type="submit" value="Submit" name="submit"/>
</form>
<?php
if (isset($_POST['submit'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$check = new newPHPClass();
$check->checkLogin($username, $password);
}
?>
和班级
include '../con_db/connect.php';
class newPHPClass {
public function checkLogin($username, $password) {
$select = mysql_query('SELECT * FROM users WHERE username = "' . $username . '" AND password = "' . $password . '"');
if (count($select) > 0) {
echo "true";
return true;
} else {
echo "false";
return false;
}
}