Free Web Hosting Forum
Go Back   Free Web Hosting Forum > Website Building > Web Programming
Reload this Page [PHP] Help with connecting to MySQL Databse
Reply
 
Thread Tools Display Modes
(#1 (permalink))
Old
Junior Member
leojwinter is on a distinguished road
 
Posts: 2
Join Date: Jan 2012
Default [PHP] Help with connecting to MySQL Databse - 01-20-2012, 09:23 PM

I'm trying to code a log in and registration feature but I'm having trouble connecting to my MySQL server, I'm sure all my credentials are correct, just not sure I've applied them correctly.

I named both the database and username the same as an example, still no connection. It wants to connect to a table in the database called 'users'.

Thanks a lot.

Connection code:
PHP Code:
<?php

$username 
$_POST['username'];
$password $_POST['password'];

if (
$username && $password) {
    
$connect mysql_connect("mysql16.000webhost.com""a6128086_users""password") or die ("Couldn't connect!");
    
mysql_select_db("a6128086_users"$connect) or die("Unable to locate database.");    
}
else
    die(
"Please enter a Username and Password.");

?>
Reply With Quote
Sponsored Links
(#2 (permalink))
Old
d3iti's Avatar
Super Moderator
d3iti is on a distinguished road
 
Posts: 4,609
Join Date: Jul 2009
Location: Spain
Default 01-21-2012, 08:51 AM

Hi,
Are you getting any error MySQL server?
Would be good to see error returns on the connection MySQL server.


Si este mensaje te ha servido de ayuda no dudes en pulsar sobre el botón karma
Reply With Quote
(#3 (permalink))
Old
Junior Member
leojwinter is on a distinguished road
 
Posts: 2
Join Date: Jan 2012
Default 01-21-2012, 10:46 AM

Quote:
Originally Posted by d3iti View Post
Hi,
Are you getting any error MySQL server?
Would be good to see error returns on the connection MySQL server.
Hi, only error I receive is the one I setup.

"Please enter a Username and Password."
Reply With Quote
(#4 (permalink))
Old
d3iti's Avatar
Super Moderator
d3iti is on a distinguished road
 
Posts: 4,609
Join Date: Jul 2009
Location: Spain
Default 01-21-2012, 10:56 AM

One way to see what problems you have with the piece of code you've written before is changing that part of code with the following code:

PHP Code:
<?php

$username 
$_POST['username'];
$password $_POST['password'];

if (
$username && $password) {
    
$connect mysql_connect("mysql16.000webhost.com""a6128086_users""password") or die ("Couldn't connect!" .mysql_error());
    
mysql_select_db("a6128086_users"$connect) or die("Unable to locate database." .mysql_error());    
}
else
    die(
"Please enter a Username and Password.");

?>


Si este mensaje te ha servido de ayuda no dudes en pulsar sobre el botón karma
Reply With Quote
(#5 (permalink))
Old
diwanguard's Avatar
Junior Member
diwanguard is on a distinguished road
 
Posts: 1
Join Date: Jan 2012
Location: Indonesia
Default 01-26-2012, 06:15 AM

<?php

if(!defined('INCLUDE_CHECK')) die('You are not allowed to execute this file directly');


/* Database config */

$db_host = 'mysql3.000webhost.com';
$db_user = 'MySQL user name';
$db_pass = 'MySQL user pass';
$db_database = 'MySQL database name';

/* End config */



$link = mysql_connect($db_host,$db_user,$db_pass) or die('Unable to establish a DB connection');

mysql_select_db($db_database,$link);
mysql_query("SET names UTF8");

?>
Reply With Quote
(#6 (permalink))
Old
Junior Member
biazzotto is on a distinguished road
 
Posts: 2
Join Date: Feb 2012
Lightbulb 02-09-2012, 02:59 PM

If you are using <form action="file.php" method="GET">, try replacing
PHP Code:
$username $_POST['username'];
$password $_POST['password']; 
with
PHP Code:
$username $_GET['username'];
$password $_GET['password']; 
Reply With Quote
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

Forum Jump



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