Log in

View Full Version : Login script PHP



Mattphp
06-02-2010, 01:26 PM
http://www.phpeasystep.com/phptu/6.html

Hello,

Could any help with understanding the code of the login script in the above link. Basically its the following section that I need to understand. I'm not entirely sure how to connect to the server and database:

<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
$tbl_name="members"; // Table name


thanks!

Beverleyh
06-02-2010, 01:55 PM
$host="localhost"; is the database server for your webhost. If localhost doesnt work, it might be something like "db1.webhost.com". CHeck in your Control Panel if unsure.
$username=""; is the username you use to log into your databases/phpMyAdmin panel - it might use your accountname as a prefix, such as "matt_dbuser". This might also be the name of the database too.
$password=""; Is the password you setup when creating your database via your webhost.
$db_name="test"; is the name of the database you created with your webhost - might be the same as the "$username" value. You need to set this up before you start connection with the script in the tutorial.

Hope that helps

djr33
06-02-2010, 02:41 PM
Connecting to MySQL should be very easy. But it's often hard because you don't know the correct information from the host. It's also hard because if you don't know this information, you can't test the code to begin to understand it.
So my suggestion is that you look up the "connect to mysql" on your host's website. They usually have examples.

Many hosts have unpredictable mysql server names, so you won't ever get it to work unless you know that.

Once you have the correct info, just fill it in like you have.