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;
}
?>
And this is my form:
<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>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…