Garcia Posted January 10, 2007 Share Posted January 10, 2007 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 13Couldn't execute query 2.[/quote]Here is my code for login.php[code]<?php//login pagerequire ("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 More sharing options...
marcus Posted January 10, 2007 Share Posted January 10, 2007 [code=php:0]$result2 = mysql_query($sql,$con)[/code] Link to comment Share on other sites More sharing options...
magic2goodil Posted January 10, 2007 Share Posted January 10, 2007 agreed Link to comment Share on other sites More sharing options...
Jessica Posted January 10, 2007 Share Posted January 10, 2007 It's in several places, btw. Link to comment Share on other sites More sharing options...
Garcia Posted January 10, 2007 Author Share Posted January 10, 2007 Ah thanks fixed thatbut 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 16Couldn't execute[/quote]Updated code[code]<?php//login pagerequire ("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 More sharing options...
Jessica Posted January 10, 2007 Share Posted January 10, 2007 Where is $con defined? Link to comment Share on other sites More sharing options...
Garcia Posted January 10, 2007 Author Share Posted January 10, 2007 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 More sharing options...
Jessica Posted January 10, 2007 Share Posted January 10, 2007 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 $_POSTPlus you need to use $_POST['var'] not $_POST[var]PS: It's should have, not should of. Link to comment Share on other sites More sharing options...
marcus Posted January 10, 2007 Share Posted January 10, 2007 If you're directly connecting to your database there is no need to include the $con in your mysql queries. Link to comment Share on other sites More sharing options...
Garcia Posted January 10, 2007 Author Share Posted January 10, 2007 Well I know for a fact that config.php works properly because of previous scripts I used with it. Link to comment Share on other sites More sharing options...
Garcia Posted January 10, 2007 Author Share Posted January 10, 2007 Ahhh my fault. I didn't realize it was pointing me to members.php which had the error and I will fix that one later.Thanks all for the help. Link to comment Share on other sites More sharing options...
magic2goodil Posted January 10, 2007 Share Posted January 10, 2007 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 More sharing options...
Jessica Posted January 10, 2007 Share Posted January 10, 2007 magic that's not true.But yes, you can take it out. Link to comment Share on other sites More sharing options...
magic2goodil Posted January 10, 2007 Share Posted January 10, 2007 Really, it's not true? Last time I checked if I use require() on a file and a variable is defined in that file that is required and i try and call it directly without it being global ont he main page..it doesn't work..but maybe life hates me :( Link to comment Share on other sites More sharing options...
Jessica Posted January 10, 2007 Share Posted January 10, 2007 It's always worked for me. Maybe it's an ini setting. Link to comment Share on other sites More sharing options...
Garcia Posted January 10, 2007 Author Share Posted January 10, 2007 Yes I always had $con and works fine for me. Don't worry I got the problem fixed and it didn't have to do with that. Link to comment Share on other sites More sharing options...
Recommended Posts