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
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]
Link to comment
Share on other sites

[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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.