Jump to content

Login Error


Garcia

Recommended Posts

I am trying to pin point my error for awhile not sure why. I get the following error
[quote]
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/garcia/public_html/support/login.php on line 13
Couldn't execute query 2.
[/quote]

Here is my code for login.php

[code]
<?php
//login page
require ("config.php");

$sql = "SELECT username FROM members WHERE username='$_post[username]'";
$rs = mysql_query($sql, $con)
or die ("Couldn't execute query.");
$num = mysql_num_rows($rs);
if ($num > 0) // login name found!
{
$sql = "SELECT username From members WHERE username='$_POST[username]'
AND password=md5('$_POST[password]')";
$result2 = mysql_query($con, $sql)
                or die ("Couldn't execute query 2.");
$num2 = mysql_num_rows ($result2);
if ($num > 0) //correct passy
{
$_SESSION['auth'] = "yes";
$logname=$_POST['username'];
$_SESSION['logname'] = $logname;
$today = date("Y-m-d h:i:s");
$sql = "INSERT INTO Login (loginName, loginTime)
      VALUES ('$logname', '$today')";
$result = mysql_query ($con, $sql)
or die ("Couldn't execute query");
header ("Location: members.php");
}
      else
{
  $message = "The Login Name, '$_POST[username]' exists, but you have not entered the correct password!<br/>";
  include ("login_form.php");
}
}
elseif ($num == 0)
{
$message = "Login Name does not exist";
include ("login_form.php");
}

?>
[/code]

I haven't coded the login_form.php but I doubt that would have that kind of error.

Thanks,
Link to comment
Share on other sites

Ah thanks fixed that

but now get this
[quote]
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/garcia/public_html/support/members.php on line 16
Couldn't execute
[/quote]

Updated code
[code]
<?php
//login page
require ("config.php");

$sql = "SELECT username FROM members WHERE username='$_post[username]'";
$rs = mysql_query($sql, $con)
or die ("Couldn't execute query.");
$num = mysql_num_rows($rs);
if ($num > 0) // login name found!
{
$sql = "SELECT username From members WHERE username='$_POST[username]'
AND password=md5('$_POST[password]')";
$result2 = mysql_query($sql,$con)
                or die ("Couldn't execute query 2.");
$num2 = mysql_num_rows ($result2);
if ($num > 0) //correct passy
{
$_SESSION['auth'] = "yes";
$logname=$_POST['username'];
$_SESSION['logname'] = $logname;
$today = date("Y-m-d h:i:s");
$sql = "INSERT INTO Login (loginName, loginTime)
      VALUES ('$logname', '$today')";
$result = mysql_query ($sql, $con)
or die ("Couldn't execute query");
header ("Location: members.php");
}
      else
{
  $message = "The Login Name, '$_POST[username]' exists, but you have not entered the correct password!<br/>";
  include ("login_form.php");
}
}
elseif ($num == 0)
{
$message = "Login Name does not exist";
include ("login_form.php");
}

?>
[/code]
Link to comment
Share on other sites

Sorry should of showed you the config

[code]
<?php
$host = "localhost";
$dbUser = "garcia_ticketsys";
$dbPass = "*********";
$database = 'garcia_ticketsystem';

$con = mysql_connect("$host", "$dbUser", "$dbPass");
if (!$con)
{
die('Could not connect: ' .mysql_error() );
}

@mysql_select_db($database) or die( 'Unable to select database');

?>
[/code]
Link to comment
Share on other sites

If you have @, does the or die still take effect? I don't know - what happens if you take out the @ on your select_db?
you have $_post instead of $_POST

Plus you need to use $_POST['var'] not $_POST[var]
PS: It's should have, not should of.
Link to comment
Share on other sites

the error is because you are trying to call the link $con which is defined in your config page.

it will not pass to the members.php unless defined as a global.

you can just take it out though of your queries so it reads mysql_query($sql); like mgallforever mentioned
Link to comment
Share on other sites

Guest
This topic is now 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.