SQL Question

Survey in Mysql

I really need some help with this survey. I want to insert it into phpmyadmin. I'm studying and i need this for a project.

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<link rel="stylesheet" href="style.css" type="text/css"/>
<script src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
<script src="script.js"></script>
</head>
<body>
<div>
<form action="action.php" method="get">
<h1>KÆLEDYR</h1>
<h3>Oplysninger om dig</h3>
Navn:<br>
<input type="text" name="name" value="Navn"><br><br>
Email:<br>
<input type="email" name="email" value="navn@gmail.com"><br><br>
Køn:<br>
<input type="radio" name="gender" value="male" checked> Mand<br>
<input type="radio" name="gender" value="female"> Kvinde<br>
<input type="radio" name="gender" value="other"> Ved ikke<br><br>
Alder:
<input type="number" name="age" value="ex.20"><br><br>

<h3>Har du kæledyr?</h3>
Har du kæledyr?:<br>
<input type="radio" name="yes" value="yes" checked>Ja<br>
<input type="radio" name="no" value="no">Nej<br><br>

Hvis ja, hvor mange har du?:
<input type="number" name="pet-number" value="ex.20"><br><br>

Hvilke kældedyr har du?:
<br>
<input type="checkbox" name="animal1" value="Hund">Hund
<br>
<input type="checkbox" name="animal2" value="Kat">Kat
<br>
<input type="checkbox" name="animal3" value="Reptil">Reptil
<br>
<input type="checkbox" name="animal4" value="Fugl">Fugl
<br>
<input type="checkbox" name="animal5" value="Fisk">Fisk
<br>
<input type="checkbox" name="animal6" value="Hest">Hest
<br>
<input type="checkbox" name="animal6" value="andet">Andet
<br><br>

Kældedyrs quiz:
<br>
En dalmatiner er stribet?:
<br>
<input type="radio" name="true" value="true" checked>Sandt<br>
<input type="radio" name="false" value="false">Falsk<br><br>
<br>
En hest har 5 ben:
<br>
<input type="radio" name="true" value="true" checked>Sandt<br>
<input type="radio" name="false" value="false">Falsk<br><br>

<input type="submit">
</form>
</div>

</body>
</html>


My action.php looks like this.

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>

<?php
/*
File: action.php
Purpose: INSERT INTO ...
*/

$mysqli = new mysqli("localhost", "root", "","survey"); // creates the object
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; // if error messages
}

echo "You're connected to the database via: "
. $mysqli->host_info
. "\n";



if($_GET) {
/*
$fn = $_GET['firstName'];
$ln = $_GET['lastName'];

// format the sql
$sql = "INSERT INTO `sakila`.`actor` (`actor_id`, `first_name`, `last_name`, `last_update`) VALUES (NULL, '"
. $fn
. "', '"
. $ln
. "', CURRENT_TIMESTAMP);";
*/
// INSERT
$sql = "INSERT INTO `person` (`name`, '".$_GET['name']."')";
echo $_GET["name"];


$insert = $mysqli->query($sql);

echo "<p>et svar her ....</p>";
echo $sql;

}
else {
echo "<p>Error: Use the form please. No GET got.</p>";
}

?>
</body>
</html>


How do i proceed and get my survey into the database?

Answer

You're inserting the data in the wrong way. Your query should be like this:

//FOR SINGLE ITEM
    $sql = "INSERT INTO `person` (`name`) VALUES ('".$_POST['name']."')";
//FOR MULTIPLE ITEMS
    $sql = "INSERT INTO `person` (`name`,`email`,`gender`) VALUES ('".$_POST['name']."','".$_POST['email']."','".$_POST['gender']."')";

See PHP Insert Data Into MySQL