it is a error in the VALUES in the php. It says it is a undefined index in every single value. I have tried for a long time now, but i can't figure out what the problem is. is it in my database or inside the code? Please help me :)
<html>
<body>
<h1>A small example page to insert some data in to the MySQL database using PHP</h1>
<form action="insert.php" method="post">
Firstname: <input type="text" name="navn" /><br><br>
Lastname: <input type="text" name="adresse" /><br><br>
<input type="submit" />
</form>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("forum", $con);
$sql="INSERT INTO bruker (navn, adresse)
VALUES
('$_POST[navn]',
'$_POST[adresse]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con)
?>
</body>
</html>
mysql_functions and switch to MySQLi or PDO instead 2) Don't blindly insert values into your MySQL query. Your code is vulnerable to SQL injection 3) You can useisset()to check if the value is actually defined in your$_POSTarray.print_r($_POST);will list the entire contents.$_POST[navn]it's in fact$_POST['navn']and$_POST['adresse']. But you've got bigger issues than that: you're blindly inserting values in the database. That's a big no-no. You should look into prepared statements and usemysqliinstead.