I can't get this code to set the input in form to my database, and I can't figure out why. Is there any that can help me figure you why?
I'm trying to use the form to get input from user.
<form action="" method="post">
Etternavn:<br>
<input type="text" name="etternavn" id="etternavn" placeholder="Etternavn"><br>
Fornavn:<br>
<input type="text" name="fornavn" id="fornavn" placeholder="Fornavn"><br>
Klasse:<br>
<input type="text" name="klasse" id="klasse" placeholder="Klasse"><br>
Mobil:<br>
<input type="text" name="mobli" id="mobil" placeholder="Mobil"><br>
Nettside:<br>
<input type="text" name="www" id="www" placeholder="Nettside"><br>
Epost:<br>
<input type="email" name="epost" id="epost" placeholder="Epost">
<input type="submit" name="submit" value="Submit">
</form>
Here I'm running the PHP PDO to get hold in the database and try to put the user input in to the database but I can't see why it doesn't work. I don't get any messages that tell me that anything is wrong.
<?php
if (isset($_POST["submit"])){
$host = "kark.hin.no";
$dbname = "stud_v16_klemetsen";
$username = "v16_klemetsen";
$password = "**********";
try {
$dbh = new PDO("mysql:host=$host;dbname=$dbname",$username,$password);
$dbh->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
$q = $dbh->prepare("INSERT INTO studenter(etternavn,fornavn,klasse,mobil,www,epost)
VALUES (:etternavn, :fornavn, :klasse, :mobil, :www, :epost");
$q->bindParam(':etternavn',$_POST['etternavn'],PDO::PARAM_STR);
$q->bindParam(':fornavn',$_POST['fornavn'],PDO::PARAM_STR);
$q->bindParam(':klasse',$_POST['klasse'],PDO::PARAM_STR);
$q->bindParam(':mobil',$_POST['mobil'],PDO::PARAM_STR);
$q->bindParam(':adr',$_POST['www'],PDO::PARAM_STR);
$q->bindParam(':epost',$_POST['epost'],PDO::PARAM_STR);
$q->execute();
$q->execute();
echo "succssfull";
}
catch (PDOException $e){
echo "ERROR" . $e->getMessage();
}
$dbh = null;
}
?>