View Full Version : Trouble connecting to database

09-06-2011, 03:06 PM
I've been working on this code for 2 days and can't seem to find my error.

/*Create the MYSQL Insert*/

$connection =mysql_connect($dbhost, $dbuser, $dbpass) or die(mysql_error());
if ($connection) {
$msg = "success!";
echo $msg;

$dbname = "naplesbr_wrd1";

$caltable = "wp_calendar";
$sql = "insert into " ;
$sql .= $caltable ;
$sql .= " (event_id, event_begin, event_end, event_title, event_desc, event_time, event_recur, event_repeats, event_author, event_category, event_link) VALUES ('',$start_date, $end_date, $title, '', $game_time,$recur, $repeat, $author, $category, $link)";
$sql_result = mysql_query($sql) or die(mysql_error());

Please help.


09-06-2011, 03:33 PM
Where error are you getting/seeing? What you posted has an extra closing brace that isn't matched with anything which would likely result in a PHP failure.

09-06-2011, 03:46 PM
Is event_id an auto increment? if so trying to insert it with ' ' will throw you an error. Either leave the column out entirely or use NULL (with no quotes around it) in place of ' ' where you have it now.

And posting the actual error message, whether mysql, php or telling us the screen is blank or your computer falls off the desk or whatever will help us assist you better.

I'm guessing the auto_increment above because i've seen people make that mistake a number of times.

09-06-2011, 03:58 PM
The error msg is No database selected

09-06-2011, 03:59 PM
I removed the auto-increment field as well as the other blank field and still get the same mysql msg No database selected

09-06-2011, 05:34 PM
Take the error suppression off of your connect and add a die in case it fails and see what the error is.

mysql_select_db($dbname) or die(mysql_error());

09-06-2011, 06:43 PM
Access denied for user 'naplesbr_upload'@'localhost' to database 'naplesbr_wrd1'

09-06-2011, 07:34 PM
That pretty much says it all. That user isn't authorized to use that database.