isset value always returns 1(isset 值总是返回 1)
问题描述
我是 PHP 的新手.我正在尝试制作登录和注销网页.现在,我创建了一个可以添加记录的页面.我的代码总是从我构建的表单中返回 1,而不管表单中的值如何.我的代码-
I am a newbie when it comes to PHP. I am trying to make a login and logout webpage. Now, I have created a page which would add records. MY code always returns 1 from the form that i built, irrespective of the value in the form. My code-
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$alpha = isset($_GET["username"]);
$beta = isset($_GET["password"]);
$gama = isset($_GET["hobby"]);
// Create connection
$conn = mysqli_connect("localhost","root" ,"","member");
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "INSERT INTO data (username,password,hobby)
VALUES ($alpha, $beta, $gama)";
if ($conn->query($sql)=== TRUE) {
echo $alpha."Your record is added into our database ";
} else {
echo $sql.$conn->error;
}
?>
这是我的表格:
<form action="add.php">
<table>
<tr>
<td>Username :</td> <td><input type="text" name="username"></td>
</tr>
<tr>
<td>Password :</td> <td><input type="text" name="username"></td>
</tr>
<tr>
<td>Hobbies:</td> <td><textarea name="hobby" id="hobby" cols="22" rows="7"></textarea></td>
</tr>
<tr>
<td> </td><td><input type="submit" name="submit"></td>
</tr>
</table>
</form>
推荐答案
发生这种情况是因为 isset() 返回一个布尔值.
It happens because isset() returns a boolean value.
如果你想直接打印username字段,你可以:
If you want to directly print the username field you can just:
if(isset($_GET["username"])) {
echo $_GET["username"];
}
所以你应该明白变量 $alpha, $beta, $gamma 不保存你期望的实际字符串,而是一个布尔值价值
So you should understand that the variables $alpha, $beta, $gamma do not hold the actual string you expect but a boolean value
查看更多信息:http://php.net/manual/en/function.isset.php
这篇关于isset 值总是返回 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:isset 值总是返回 1
- 使用 GD 和 libjpeg 支持编译 PHP 2022-01-01
- 如何使用 Google API 在团队云端硬盘中创建文件夹? 2022-01-01
- 如何从数据库中获取数据以在 laravel 中查看页面? 2022-01-01
- 如何在 Symfony2 中正确使用 webSockets 2021-01-01
- PHP - if 语句中的倒序 2021-01-01
- 覆盖 Magento 社区模块控制器的问题 2022-01-01
- Laravel 5:Model.php 中的 MassAssignmentException 2021-01-01
- Oracle 即时客户端 DYLD_LIBRARY_PATH 错误 2022-01-01
- PHP foreach() 与数组中的数组? 2022-01-01
- openssl_digest vs hash vs hash_hmac?盐与盐的区别HMAC? 2022-01-01
