Jump to content

Login php


Sianna

Recommended Posts

so, i am extremely new to php so forgive my lack of knowledge with this!

 

i am trying to get a login php script to work, but can not figure it out for the life of me.

 

when i go to login(with any login name/password), i get this error:

 

Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'user_here'@'gator375.hostgator.com' (using password: YES) in /home/ladadada/public_html/sitename.com/route/check.php on line 9

cannot connect

 

i had created the database, everything from a tutorial so it is possible that i screwed some stuff up, but, this appears to be something wrong with the script not necessarily the database :confused:

 

?php

$host="host_name_here"; // Host name

$username="username_here"; // Mysql username

$password="password_here"; // Mysql password

$db_name="DB_name_here"; // Database name

$tbl_name="TB_name_here"; // Table name

 

// Connect to server and select databse.

mysql_connect("$host", "$username", "$password")or die("cannot connect");

mysql_select_db("$db_name")or die("cannot select DB");

 

that is everything up to line 9, all the info filled out but in this preview just showing where i had put the info. - i guess one confusion would be the host name! i wasn't sure if it was the IP or something like 'sitehere.com'.  :shrug: if anyone could tell me exactly how that information should be filled out it would be very appreciated, or, if i'm doing it completely wrong!

 

thanks!

Link to comment
Share on other sites

Hai  change this code

?php
$host="host_name_here"; // Host name
$username="username_here"; // Mysql username
$password="password_here"; // Mysql password
$db_name="DB_name_here"; // Database name
$tbl_name="TB_name_here"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");

 

to some thing like this

 

<?php
$host="localhost"; // Host name
$username="username_here"; // Mysql username
$password="password_here"; // Mysql password
$db_name="DB_name_here"; // Database name
$tbl_name="TB_name_here"; // Table name

// Connect to server and select databse.
mysql_connect($host, $username, $password)or die("cannot connect");
mysql_select_db($db_name)or die("cannot select DB");

 

are u sure is this file which is giving a problem...

can u copy the check.php file

 

Link to comment
Share on other sites

sure. here is the entire check.php file

 

<?php
$host="host_name_here"; // Host name
$username="username_here"; // Mysql username
$password="password_here"; // Mysql password
$db_name="DB_name_here"; // Database name
$tbl_name="TB_name_here"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
mysql_select_db("$db_name")or die("cannot select DB");

// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];

// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "loggedin.php"
session_register("myusername");
session_register("mypassword");
header("location:loggedin.php");
}
else {
echo "Wrong Username or Password";
}
?>

Link to comment
Share on other sites

mysql_connect("$host", "$username", "$password")or die("cannot connect");

mysql_select_db("$db_name")or die("cannot select DB");

mysql_select_db("$db_name")or die("cannot select DB");

 

in this remove the double qoutes from

mysql_connect("$host", "$username", "$password")
mysql_select_db("$db_name")

 

and make it some thing like this

 

mysql_connect($host, $username, $password)or die("cannot connect");
mysql_select_db($db_name)or die("cannot select DB");

Link to comment
Share on other sites

just did what you suggested and i seem to be getting the same error. i also changed the host name to localhost as suggested by a previous poster. not really sure why this isn't working, maybe the tutorial and all its information was oudated :confused:.

 

that being said, anyone know of a fluent login tutorial that does work?

Link to comment
Share on other sites

The screen where you created your database, the database user/password, and assigned that user/password permission to access the database should have also displayed the correct hostname or IP address to use for accessing the correct database server for your hosting account (most larger web hosts have multiple database servers and assign your account a specific one to use.)

 

Edit: also many web hosts require that your database name and username be a combination of your web hosting user name - see this relevant link from the hostgator FAQ section - http://support.hostgator.com/articles/cpanel/how-to-connect-to-the-mysql-database

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.