Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Trouble connecting to database

    I've been working on this code for 2 days and can't seem to find my error.

    Code:
    /*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

  • #2
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,307
    Thanks
    4
    Thanked 205 Times in 202 Posts
    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.
    Dave .... HostMonster for all of your hosting needs

  • #3
    Super Moderator guelphdad's Avatar
    Join Date
    Mar 2006
    Location
    St. Catharines, Ontario Canada
    Posts
    2,634
    Thanks
    4
    Thanked 148 Times in 139 Posts
    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.

  • #4
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The error msg is No database selected

  • #5
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I removed the auto-increment field as well as the other blank field and still get the same mysql msg No database selected

  • #6
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,307
    Thanks
    4
    Thanked 205 Times in 202 Posts
    Take the error suppression off of your connect and add a die in case it fails and see what the error is.

    PHP Code:
    mysql_select_db($dbname) or die(mysql_error()); 
    Dave .... HostMonster for all of your hosting needs

  • #7
    New to the CF scene
    Join Date
    Sep 2011
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Access denied for user 'naplesbr_upload'@'localhost' to database 'naplesbr_wrd1'

  • #8
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,307
    Thanks
    4
    Thanked 205 Times in 202 Posts
    That pretty much says it all. That user isn't authorized to use that database.
    Dave .... HostMonster for all of your hosting needs


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •