好的,你有一个HTML表单和一些PHP代码来处理表单提交时发生的情况。
因此,当表单被提交时,为了PHP注册此提交需要知道该表单已提交。
如果您正在通过JavaScript处理表单输入,但您在PHP中有一些不同,您可以在客户端上使用表单,但在PHP中它有点不同。
所以你的形式将需要两个额外的东西:
1)指定的表单数据将如何被发送的方法属性。
2.)定义表单数据将被发送到何处的动作。
最常用的方法是GET和POST。而当你有PHP代码处理与表单相同页面上的表单时,这个动作就是这个页面本身。所以,你现在有:
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
<input type="text" name="id">
<input type="text" name="name">
<input type="text" name="city">
<input type="submit" name="clicked" value="formSubmit">
</form>
在PHP为了您注册此输入,您可以使用提交按钮被点击时发生的事件。所以,你将有:
<?php
# If the submit button was clicked
if (isset($_POST['clicked']) && $_POST['clicked'] == 'formSubmit') {
# Access the form inputs in php
$id = $_POST['id'];
$name = $_POST['name'];
$city = $_POST['city'];
# Helper to output mysql errors
function processError($link) {
echo "Error: Unable to connect to MySQL.<br>";
echo "Debugging errno: " . $link->errno . "<br>";
echo "Debugging error: " . $link->error . "<br>";
exit;
}
# Connect to the database
// Create a database connection for PHP to use
$link = mysqli_connect($DBHost, $DBUser, $DBPass, $DBName);
// Ensure the connection is active
if (!$link) {
echo "Error: Unable to connect to MySQL.<br>";
echo "Debugging errno: " . mysqli_connect_errno() . "<br>";
echo "Debugging error: " . mysqli_connect_error() . "<br>";
exit;
}
// Sets encoding type to uft8
if (!mysqli_set_charset($link, 'utf8')) { processError($link); }
# Do query
// Build query
$query = 'SELECT `id` ';
$query .= 'FROM `eval` ';
$query .= 'WHERE `id` = ? ';
$query .= 'AND `name` = ? ';
$query .= 'AND `city` = ? ';
$query .= 'LIMIT 1 ';
// Prepare the statement
if (!$stmt = $link->prepare($query)) { processError($link); }
// Bind in form values to prevent sql injection
if (!$stmt->bind_param('iss', $id, $name, $city)) { processError($link); }
// Execute the query
if (!$stmt->execute()) { processError($link); }
// Store the result
$stmt->store_result();
// Store the number of rows returned
$num_rows = $stmt->num_rows;
// Close the statement
$stmt->close();
# Check if the record exists
if ($num_rows == 1) {
echo 'Record already exist...<br/>';
}
// No record exists
else {
echo '<a href="NewUser.php"> New Sign Up </a>';
}
}
?>
希望帮助你:-)
任何想法,将不胜感激,以获得所需的结果,查询可以是任何东西,但需要路由到用户之前,检查所有这三场下一页... – A1Nasir