Jump to content

[SOLVED] Simple login script not working?


toxictoad

Recommended Posts

hi all,

i'm working through some tutorials on php and mysql and have hit a problem i can't work out.

i have created a new user account for the mysql database. i have tested it, by logging in - (mysql -u phpuser -p) and that's fine. the next thing was to get a web page to send the login details and connect to the specified database (newdb)

this is where i'm at...

i've created a directory in my web root directory called 'config' and have 1 php file in there 'db_config.php'

this is the script:

<?php
$db_host = "localhost";
$db_user = "phpuser";
$db_password = "myp4ssword";
$db_name = "newdb";
?>

then i have this script saved in the web root directory:

<?php
require($_SERVER["DOCUMENT_ROOT"]."/config/db_config.php");
$connection = mysql_connect($db_host, db_user, $db_password) or die("error connecting");
echo "connection made";
?>

has anyone got any ideas on why i can't connect using these?

ps i've installed the latest wamp

thanks
Link to comment
https://forums.phpfreaks.com/topic/32064-solved-simple-login-script-not-working/
Share on other sites

You're missing a '$' in front of 'db_user' and you need to select a database:

[code]
<?php
  require($_SERVER["DOCUMENT_ROOT"]."/config/db_config.php");
  $connection = mysql_connect($db_host, $db_user, $db_password) or die("error connecting");
  $db = mysql_select_db("$db_name", $connection) or die("Unable to select database!");
  echo "connection made";
?>

[/code]
[quote author=bljepp69 link=topic=120148.msg492639#msg492639 date=1167324558]
You're missing a '$' in front of 'db_user' and you need to select a database:

[code]
<?php
  require($_SERVER["DOCUMENT_ROOT"]."/config/db_config.php");
  $connection = mysql_connect($db_host, $db_user, $db_password) or die("error connecting");
  $db = mysql_select_db("$db_name", $connection) or die("Unable to select database!");
  echo "connection made";
?>

[/code]
[/quote]

oh boy  :-[
thanks bljepp69, much appriciated

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.