...

View Full Version : Trouble connecting to database



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



/*Create the MYSQL Insert*/

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

$dbname = "naplesbr_wrd1";
@mysql_select_db($dbname);

$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.

Thanks

djm0219
09-06-2011, 02: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.

guelphdad
09-06-2011, 02: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.

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

saltschuler
09-06-2011, 02: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

djm0219
09-06-2011, 04: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());

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

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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum