Hey,
I have three files - all three shown in code below. The error is also shown. The only way to get this error to go away is to put the database name in front of the table name, even though the mysql_select_db has been defined in db.php.
Hopefully this make sense...
Below is db.php
<?
$dbhost = "localhost";
$dbname = "my_test";
$dbpassword = "mypass";
$connect = mysql_connect("$dbhost","$dbname","$dbpassword");
mysql_select_db("my_database",$connect);
?>
Below is functions.php
<?
function createCase( $case_id, $case_comments ) {
$timestamp = time();
mysql_query("INSERT INTO case
(case_id, case_timestamp, case_comments) VALUES ('$case_id', '$timestamp', '$case_comments')") or die(mysql_error());
echo "Case \"$case_id\" was successfully created!";
}
?>
Below is query.php (the active executed file)
<?
require("inc/db.php");
require("inc/functions.php");
createCase("TEST-111","This is a test");
?>
The error I get is this:
You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'case (case_id, case_timestamp, case_comments) VALUES ('SET
If I change the above SQL query instead of saying "INSERT INTO case" to say "INSERT INTO my_database.case" it works fine. It seems like the require is not working for the functions file like I would expect. I don't want to have to hard-code that database name everywhere as it will change. How can I get functions.php to use the mysql_select_db? Re-requiring that file directly in functions.php didn't work either.
Thanks so much!