Author Topic: Can't access mysql once I put site online  (Read 206 times)

traydavid

  • Regular Member
  • **
  • Posts: 51
  • Karma: 0
    • View Profile
Can't access mysql once I put site online
« on: August 03, 2012, 11:19:04 AM »
I can access fine on my WAMP server on my computer.  Put online and storefront is visible, so I know the login code works to show the products.  No problem.  But when I try to login as admin, can't connect to db error OR could not validate userid/pwd error.  Have tried various combos of userid, pwd, code changes to no avail.  Any help is appreciated.

This is the validate code that validates the login:

PHP Code: [Select]

session_start
();
include (
"../mylibrary/smalllogin.php");
smalllogin();

$userid $_POST['userid'];
$password $_POST['password'];
$query "SELECT * from admins where userid = '$userid' and password = ('$password')";
$result mysql_query($query);
if (
mysql_num_rows($result) == 0)
{
   echo 
"<h2>Sorry, your account was not validated.</h2><br>\n";
   echo 
"<a href=\"smalladmin.php\">Try again</a><br>\n";
} else
{
   
$_SESSION['store_smalladmin'] = $userid;
   
header("Location: smalladmin.php");
}


This is the login form, which triggers the login php and validate php:

PHP Code: [Select]
<h2><br>Store Web Site Administration<br></h2>

<
p>Please log in below</p>
<
form action="smallvalidate.php" method="post">
<
b>User Name:</b><br>
<
input type="text" size="20" name="userid"><br>
<
br>
<
b>Password:</b><br><input type="password" size="20" name="password">
<
br><br>
<
input type="submit" value="smalllogin">
</
form>


And this is the login php:

PHP Code: [Select]

function smalllogin()
{
   
$con mysql_connect("localhost""dinner1_tester""testerpa55") or die('Could not connect to server');
   
mysql_select_db("dinner1_store"$con) or die('Could not connect to database');
}


For whatever it's worth, this is the login code that displays the storefront data when someone logs on to the main site.  It's an auto login that is called in the index page and it works fine.  But it has the userid/pwd hard coded into it and that won't work for admin logins. 

PHP Code: [Select]

function login()
{
   
$con mysql_connect("localhost""dinner1_tester""tester") or die('Could not connect to server');
//dinner1 is the database name, tester is userid, tester is pwd
   
mysql_select_db("dinner1_store"$con) or die('Could not connect to database');
}


and here's the validate that is called by that:

PHP Code: [Select]

session_start
();
include (
"../mylibrary/login.php");
login();

$userid $_POST['userid'];
$password $_POST['password'];

$query "SELECT userid, name from admins where userid = '$userid' and password = ('$password')";
$result mysql_query($query);

if (
mysql_num_rows($result) == 0)
{
   echo 
"<h2>Sorry, your account was not validated.</h2><br>\n";
   echo 
"<a href=\"admin.php\">Try again</a><br>\n";
} else
{
   
$_SESSION['store_admin'] = $userid;
   
header("Location: admin.php");
}
« Last Edit: August 03, 2012, 11:23:56 AM by traydavid »

wilson382

  • Expert PHP Helper
  • Senior Member
  • *****
  • Posts: 649
  • Karma: 27
  • PHP Helper
    • View Profile
Re: Can't access mysql once I put site online
« Reply #1 on: August 03, 2012, 12:38:53 PM »
so everything works on your localhost even with an admin user?
If help you, Click the [+] Karma to thanks me