PDA

View Full Version : send a query to database



firemarshall
December 4th, 2006, 08:26 AM
Could somebody please help me before i jump out of my window!!!!
This is the first time that i am working with a database and i tought it was sepose to be easy!! Anyway i have made a form in html that is ment to send its variables to a database, i'm doing this trough a php file. So the html form is using this php file but i'm doing something wrong. i don't uderstand how u can send the variables from the html form wich input field are called artiest, plaat, winst, file1 into a table in the database. The table in the database is using the same names like so: artiest, plaat, winst, file1. Does somebody understand my problem and if you do could you be so kind not to post a tutorial but ectually change the file i just posted?? because i never understand those tutorials anyway!!!

p.s. the php file does connect to my databse but then it says this: 'Error, insert query failed'

thanks!!!!!



<?php
$username = "blabla1";
$password = "blabla2";
$hostname = "localhost";
$dbh = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
print "Connected to MySQL<br>";
// you're going to do lots more here soon

// insert data into database
mysql_select_db($dbhl);
$query = "INSERT INTO namedatabase VALUES (artiest, plaat, winst, file1)";
mysql_query($query) or die('Error, insert query failed');

mysql_close($dbh);
?>

icio
December 4th, 2006, 10:28 AM
You don't appear to have assigned a value to the variable `dbhl` and so a database cannot be selected.

<?php
// You need to give a value to this variable:
$dbhl = "databaseName";

$username = "blabla1";
$password = "blabla2";
$hostname = "localhost";
$dbh = mysql_connect($hostname, $username, $password)
or die("Unable to connect to MySQL");
print "Connected to MySQL<br>";
// you're going to do lots more here soon

// insert data into database
mysql_select_db($dbhl);
$query = "INSERT INTO namedatabase VALUES (artiest, plaat, winst, file1)";
mysql_query($query) or die('Error, insert query failed');

mysql_close($dbh);
?>

I think that should do the trick. Hope that helps :thumb: