job job - 2 months ago 17
MySQL Question

Insert data into database?

I am working on a script with a database but it has been a really long time since I learned this stuff and it is keep giving me errors and it is probably easy for you guys =)

I want the input of this

<body>
<hr> bestelling <hr>

<form action="bestellingopslaan.php" method="post">

Bestelnummer <input name="bestelnummer" type="text"> <br>
Klantnaam <input name="klantnaam" type="text"> <br>
Artikel<input name="artikel" type="text"> <br>
Prijs <input name="prijs" type="text"> <br>
<input name="verzenden" type="submit" value="Verzenden" />

</form>


to this page

<body>
bestelling opslaan


<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$dbname = '11092068';

//connection to the database
$dbhandle = mysql_connect($dbhost, $dbuser, $dbpass)
Or die("couldn't connect to SQL Server on $dbhost");

//select a database to work with
$selected = mysql_select_db($dbname, $dbhandle)
Or die("couldn't open database $dbname");

//maak de query
$insert_query = "INSERT INTO bestelling ('$_POST[bestelnummer]', '$_POST[klantnummer]', '$_POST[artikel]', '$_POST [prijs]' ) ";

if (mysql_query( $insert_query, $dbname))
{
echo "de gegevens zijn opgeslagen in de database";
}
else
{
echo "foutje";
}
?>
</body>
</body>


Here is a screenshot of my database

database

So, I hope you guys can help me out.

Answer

It would be nice to see your errors, but from looking at your code It looks like you forgottten VALUES in your query.... It should be INSERT INTO table_name (column1, column2 ,etc) VALUES.....

Comments