Jump to content

mysql function not connecting to database


surreal5335

Recommended Posts

While I have sucessfully done this in the past, I cant get it to connect for this project.

 

Here is the link to my site:

 

http://royalvillicus.com/photo_voting/db_fns.php

 

Here is my code I am using to connect:

 

function db_connect() {
	$connection = mysql_connect('localhost', '5335', '12345678');

	if (!$connection) {
		return false;
	}
}

if (!mysql_select_db('photovote')) {
	return false;
}

return $connection;

if(db_connect()) {
	echo "connected to server";
} 

 

Thanks a lot for the help

this should do the job

function db_connect() 
{		
  $connection = mysql_connect('localhost', '5335', '12345678');				
  if(!$connection) 
  {			
    return false;		
  }
  else
  {
    if(!mysql_select_db('photovote')) 
    {		
      return false;	
    }	
    else
    {
      return $connection;
    }
  }	
}		


if(db_connect()) 
{		
  echo "connected to server";	
}

 

The problem is that you wrote function unfinished then u wrote return statement outside function body etc etc. It looks like u don't understand completely how the functions must be writen

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.