Forum Moderators: coopster
He's got the database connection on an external file, so it's simply calling to that and then entering the data into a table - i replaced the variables and file names with generics for sake of example and help...
require("database.php");
database_connect();
mysql_select_db("mydatabase");
$query = "insert into table ('$var1', '$var2', '$var3', '$var4', '$var5')";
$result = mysql_query($query);
what am i doing wrong here? obviously once i pick up a bit more about PHP i won't have many errors, but it's kind of an on-the-job learning process :)
also, if anyone has a better suggestion on how I should be connecting to the database, i'm up for hearing about it. like i said, i have an inherited system, so suggestions are something i'll definitely be willing to take. thanks all!
I don't think that query will work and should return a syntax error. Add a couple more or dies and see.
require("database.php");
database_connect();
mysql_select_db("mydatabase") or die ('<p>selectdb: ' . mysql_error());
$query = "insert into table ('$var1', '$var2', '$var3', '$var4', '$var5')";
$result = mysql_query($query) or die ('<p>insertquery: ' . mysql_error());
there is also the actual connection which I assume is in 'database.php' you should look to see if that has one as well or that it handles the case where the connection fails.
another thing is the query itself
$query = "insert into table ('$var1', '$var2', '$var3', '$var4', '$var5')";
what is your table name? the syntax is slightly off as well
$query = "insert into tablename values ('$var1', '$var2', '$var3', '$var4', '$var5')";
so your query should have been giving you an error of some kind.
insert into tablename values ('value1', 'value2', 'value3', 'value4', 'value5')
the number of values must match the column count and be in the appropriate order
if you do it this way
insert into tablename (column1, column2, column3, column4, column5) values ('value1', 'value2', 'value3', 'value4', 'value5')
then you set the columns and what their values are, they don't have to match total number or order
for the record, values was originally there, but i took it out because i saw a number of web references that did not include it. no need to knock my skills :)
entry works successfully now! on to phase 3: form validation. that should be...interesting. anyone know any good tutorials?