I have written a php code to connect my html form with my database on sql (myphpadmin). But when I input information on the form and submit it, the data is showing as 1 for all the columns in sql. I am very new to coding, so it would help if you have a simple solution for this. I suspect it might be because I have not added anything in the action field of the form. I am attaching my code below.
\\\
<!DOCTYPE html>
<html>
<head>
<style>
.box{
height: 450px;
width: 400px;
background-color: #FFF4ED;
border: 4px solid #591E14;
border-radius: 25px;
padding: 25px;
}
.heading{
font-family: "Comic Sans MS", sans-serif;
font-size: 35px;
color: #591E14;
}
.space{
height: 20px;
}
.textboxid{
height:20px;
font-size:14pt;
width: 250px;
}
.textboxid1{
height:20px;
font-size:14pt;
width: 300px;
}
button{
border: 2px solid #591E14;
background-color: #C6A15B;
color: #591E14;
padding: 16px 32px;
text-align: center;
font-size: 16px;
font-family: "Comic Sans MS", sans-serif;
margin: 4px 2px;
cursor: pointer;
}
</style>
</head>
<body bgcolor="#FBECE2">
<center><br><br><br><br><br>
<form action="" method="post">
<div >
<h1 ><b>User Registration</b></h1>
<label for="User Name"><b>User Name</b></label>
<input type="text" name="User_Name" id="User_Name" required>
<br><div ></div>
<label for="User ID"><b>User ID</b></label>
<input type="text" name="User_ID" id="User_ID" required>
<br><div ></div>
<label for="User Email ID"><b>User Email ID</b></label>
<input type="text" name="User_Email_ID" id="User_Email_ID" required>
<br><div ></div>
<label for="Password"><b>Password</b></label>
<input type="Password" name="Password" id="Password" required>
<br><div ></div>
<label for="Phone No"><b>Phone No</b></label>
<input type="text" name="Phone_No" id="Phone_No" required>
<br><div ></div>
<label for="Address"><b>Address</b></label>
<input type="text" name="Address" id="Address" required>
<br><div ></div>
<!-- <button><input type="submit" value="Submit" name="Submit" id="Submit">Submit</button> -->
<button type="submit" value="Submit" name="Submit" id="Submit">Submit</button>
</div>
</form>
</center>
</body>
</html>
<?php
$servername = "localhost";
$username = "root";
$password = "sql_2022_passKEY";
$dbname = "library ms";
// Create connection
if (isset($_POST['Submit']))
{
$conn = mysqli_connect($servername, $username, $password, $dbname);
$User_Name = isset($_POST['User_Name']);
$User_ID = isset($_POST['User_ID']);
$User_Email_ID = isset($_POST['User_Email_ID']);
$Password = isset($_POST['Password']);
$Phone_No = isset($_POST['Phone_No']);
$Address = isset($_POST['Address']);
// Check connection
if ($conn->connect_error) {
die("Connection failed: "
. $conn->connect_error);
}
$sql = "INSERT INTO user_information (User_Name, User_ID, Email_ID, Password, Phone_No, Address) VALUES ('$User_Name', '$User_ID', '$User_Email_ID', '$Password', '$Phone_No', '$Address')";
if (mysqli_query($conn, $sql)) {
echo "record inserted successfully";
} else {
echo "Error: " . $sql . "" . mysqli_error($conn);}
// mysqli_close($conn);
}
?>
\\\
CodePudding user response:
Can you check if your database table has columns as varchar
or text
because that is required to save some text int cannot save text.
Example
CodePudding user response:
You’re assigning all values from isset()
function. It returns information it that variable is set, so 0 or 1. You need to take the actual value, not what isset()
returns to save to the database.
$User_Name = isset($_POST['User_Name']);
Here $User_Name
is FALSE
(0) if the value isn’t sent, TRUE
(1) otherwise.
$User_Name = $_POST['User_Name'];
Here $User_Name
is whatever was sent in POST.