简体   繁体   中英

Form data submits empty data to mySQL database

I made a form and i want all of the data to go over to a mySQL database (using PHPmyAdmin). Here is my form.

<html>
<head>

</head>
<body>
<form method="post" action="submit.php">
Interviewer <input type="text" name="interviewer"><br>
Position <input type="text" name="position"><br>
Interview Date <input type="text" name="interview_date"><br>
Candidate <input type="text" name="candidate"><br>
communication <input type="text" name="communication"><br>
appearace <input type="text" name="appearance"><br>
computer skills <input type="text" name="computer_skills"><br>
business knowledge <input type="text" name="business_knowledge"><br>
comments <input type="text" name="comments"><br>

<button type="submit">Submit</button>



</form>


</body>
</html>

All of this goes to a submit.php file which is here:

  <?php



$interviewer = (isset($_GET["interviewer"]) ? $_GET["interviewer"] : null);
$position = (isset($_GET["position"]) ? $_GET["position"] : null);
$interview_date = (isset($_GET["interview_date"]) ? $_GET["interview_date"] : null);
$candidate = (isset($_GET["candidate"]) ? $_GET["candidate"] : null);
$communication = (isset($_GET["communication"]) ? $_GET["communication"] : null);
$appearance = (isset($_GET["appearance"]) ? $_GET["appearance"] : null);
$computer_skills = (isset($_GET["computer_skills"]) ? $_GET["computer_skills"] : null);
$business_knowledge = (isset($_GET["business_knowledge"]) ? $_GET["business_knowledge"] : null);
$comments = (isset($_GET["comments"]) ? $_GET["comments"] : null);

$conn = mysqli_connect("localhost", "root", "");
if($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
mysqli_select_db($conn, "human_resources") or die(mysqli_error()); 




$sql = mysqli_query($conn, "INSERT INTO human_resources (interviewer, position, interview_date, candidate, communication, appearance, computer_skills, business_knowledge, comments) VALUES ('$interviewer', '$position', '$interview_date', '$candidate', '$communication', '$appearance', '$computer_skills', '$business_knowledge', '$comments') ") or die(mysqli_error($conn)); 



$result = mysqli_query($conn,$sql) or die( mysqli_error($conn) );
echo mysql_error();

mysqli_close($conn);
?>

I added error messages to see where I went wrong however no error messages show and the table still prints empty data to my table. I am unclear on what it can be.

You need to use $_POST instead of $_GET in your PHP Script. If you are not sure how the form input will come, use $_REQUEST .

The problem is that you POST the form but you load the GET data. Replace your $_GET code with $_POST code

您的form方法设置为POST,但是您在PHP中使用$ _GET变量,请尝试使用$ _POST。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM