Reputation: 1186
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.
Upvotes: 0
Views: 125
Reputation: 703
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
.
Upvotes: 2
Reputation: 1828
Your form method is set to POST but you're using $_GET variables in your PHP, try with $_POST instead.
Upvotes: 0
Reputation: 1707
The problem is that you POST
the form but you load the GET
data.
Replace your $_GET
code with $_POST
code
Upvotes: 1