Free Web Hosting Forum
Go Back   Free Web Hosting Forum > Website Building > Web Programming
Reload this Page cannot connect to my mysql server using php
Reply
 
Thread Tools Display Modes
(#1 (permalink))
Old
Junior Member
handuel is on a distinguished road
 
Posts: 1
Join Date: May 2012
Default 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:
<?php
if(isset($_REQUEST['attempt']))
{
$link = mysql_connect("
mysql10.000webhost.com","a8878389_*******","****** ***
") or die("
cannot connect to database
");
mysql_select_db("a8878389_*******");
$user = mysql_real_escape_string($_POST['user']);
$password = sha1(mysql_real_escape_string($_POST['password']));
$query = mysql_query("SELECT user
FROM users
WHERE user = '$user'
AND password = '$password'
") or die(mysql_error());
$total = mysql_num_rows($query);
if($total > 0)
{
echo "logged in succsefully";
}
else
{
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?
Reply With Quote
Sponsored Links
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.5.2
vBulletin Skin developed by: vBStyles.com