Possible Duplicate:
mysql_fetch_array() expects parameter 1 to be resource, boolean given in select
$connection = mysql_connect('localhost', 'username', 'password') or die('Database connection failed:' . mysql_error());
mysql_select_db('db_test', $connection) or die('Database connection failed: ' . mysql_error());
$var = '';
switch ($var) {
case 'dosomething':
break;
default:
default_func();
}
function default_func() {
if (isset($_POST['submit'])) {
$query = "INSERT INTO `table_test` (`some_field`) VALUES ('test')";
$result = mysql_query($query, $connection) or die(mysql_error());
header('Location: index.php?submit=success');
}
}
mysql_close($connection);
I have been getting a "mysql_query() expects parameter 2 to be resource null given error".
I made sure that $connection is assigned to the value of the database connection resource id, so that doesn't seem to be the problem. Don't know why the value of $connection is giving me a NULL. Any explanation as to why this error is occurring?