Vladut Maican Vladut Maican - 1 year ago 71
PHP Question

How to connect to a hosted database?

I have my databse hosted on a site.
How can I modify this:

$con=mysqli_connect("localhost", "root", "", "amit");

in order to connect to my database hoted on the www.abc.com (example) site?

Answer Source

For making the username display onto the next page, you would need to store your authenticated user's username in a session, as HTTP is a stateless protocol.

So, after you have successfully authenticated the user, set the session variable with the username.

   $_SESSION['username'] = $sUserName;
   //Then redirect the user to the account.php page
else {
 //redirect to the login page.

Once you've set the session variable you can use the variable anywhere, but don't forget to start the session at every page using, session_start() Then you can access the username on account.php as follows:

   echo $_SESSION['username'];

Also, answering your second question: Just replace "localhost" with any host of your choice to connect to a remote database engine.


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download