cannot connect to my mysql server using php -
05-07-2012, 10:46 AM
I am relatively new to this service (and am impressed, the amount offered for free is unbelievable), and am trying to create a php script that will connect to the mysql datatbase set up on the server, the information about the mysql server that I can see from mysql in cpanel is this:
mySql database: a8878389_*******
mysql user: a8878389_********
mySql host: mysql10.000webhost.com
In my database I have a table called users this currently contains 3 collumns, Id: which is an int a primary value and auto increments, a varchar named user and a varchar named password. It has one row with id as 1 (did that autimatically), a user called admin and a pasword *******
So from that information I build a php script that looks like this:
$link = mysql_connect("
") or die("
cannot connect to database
$user = mysql_real_escape_string($_POST['user']);
$password = sha1(mysql_real_escape_string($_POST['password']));
$query = mysql_query("SELECT user
WHERE user = '$user'
AND password = '$password'
") or die(mysql_error());
$total = mysql_num_rows($query);
if($total > 0)
echo "logged in succsefully";
echo "username or password was incorrect";
And I also have some html that has two text boxes that feeds the username and password into the php, however when I type admin into the username box and the correct password for the one that is stored in the table, I get this error:
Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host ' mysql10.000webhost.com' (3) in /home/a8878389/public_html/login.php on line 6 cannot connect to database
The database is running, I can edit it using phpMyAdmin, does anyone know why this wouldn't work?