0
votes

Hello i want to ask that when i am entering my values it gives no error but in database it doesn't store any values why? I Am Using Xampp v3.2.2 And MYSQLi .

image of my database https://preview.ibb.co/eTcNUR/Capture.png

i am new to php and please please help me how i solve it


Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.


<?php 

if(isset($_POST["Submit"])){

    $EName = $_POST["EName"];
    $SSN = $_POST["SSN"];
    $Dept = $_POST["Dept"];
    $Salary = $_POST["Salary"];
    $HAddress = $_POST["HAddress"];

    $servername = "localhost";
    $username = "root";
    $password = "";
    $database = "record";

    // Create connection
    $conn = mysqli_connect($servername, $username, $password, $database);
    $QUERY = "INSERT INTO emp_record(ename,ssn,dept,salary,haddress)
    VALUES('$EName','$SSN','$Dept','$Salary','$HAddress')";

    // Check connection
    if (!$conn) {
        die("Connection failed: " . mysqli_connect_error());
    }
    echo "Connected successfully";
    mysqli_query($conn,$QUERY);

}

?>



<html>

<head>

<title>Hello New To PHP</title>

</head>

<style type="text/css">

input[type="text"],textarea{

border: 1px solid dashed;
background-color: rgb(66, 244, 128);
width: 480px;
padding: .5em;
font-size: 1.0em;


}
input[type="Submit"]{
color: white;
font-size: 1.0em;
font-family: sans-serif;
width: 480px;
height: 40px;
background-color: #f44242;
}

</style>

<body>

<h1>Just Making Full Form With Database</h1>

<div>
    <form action="Insert_into_DB" method="Post">
        <fieldset>

            Employee Name :<br><input type="text" Name="EName" value=""><br>
            Social Security Number :<br><input type="text" Name="SSN" 
value=""><br>
            Department :<br><input type="text" Name="Dept" value=""><br>
            Salary :<br><input type="text" Name="Salary" value=""><br>
            Home Address :<br><textarea Name="HAddress"></textarea><br>
            <br><input type="Submit" Name="Submit" Value="Submit Your 
Record"><br>


        </fieldset>


    </form>

</div>

<?php 



?>

</body>


</html>
1
You posted the picture which shows just a structure of your table - not data.Jacek Dziurdzikowski
@ali-khan You don't actually check if there was an error or not. Try if (!mysqli_query($conn, $QUERY)) { print mysqli_error($conn); die; } --- what does it print?ob-ivan
And please, if you don't want to fall victim of a naughty hacker, read this and apply to your code: php.net/manual/en/security.database.sql-injection.phpob-ivan
Thankyou I Solve it ob-ivan thanks alotali khan

1 Answers

0
votes

You have some conflicts in database as well as in php code.

In your query and database.

$QUERY = "INSERT INTO emp_record(ename,ssn,dept,salary,haddress) VALUES('$EName','$SSN','$Dept','$Salary','$HAddress')";

In you above query salary fields with database field sallary please correct it.

New query will be.

Your code will work fine..

$QUERY = "INSERT INTO emp_record(ename,ssn,dept,sallary,haddress) VALUES('$EName','$SSN','$Dept','$Salary','$HAddress')";

Hope this will helps you

Thanks & Regards