Page 1 of 1

SQL Newbie Question

Posted: Sat Oct 12, 2002 5:08 pm
by SL-Cowsrule
I am using the exact syntax from a book, and the code is not working. all the variables have the right caps, and they are all valid field names. I dont know what the problems are, the errors are:
Warning: Supplied argument is not a valid MySQL result resource in /hsphere/local/home/twatters/gwatters.com/ta/Login Pages/Login.php on line 32

Warning: Cannot add header information - headers already sent by (output started at /hsphere/local/home/twatters/gwatters.com/ta/Login Pages/Login.php:9 in /hsphere/local/home/twatters/gwatters.com/ta/Login Pages/Login.php on line 36

Warning: Cannot add header information - headers already sent by (output started at /hsphere/local/home/twatters/gwatters.com/ta/Login Pages/Login.php:9) in /hsphere/local/home/twatters/gwatters.com/ta/Login Pages/Login.php on line 37

::

the code is:

Code: Select all

<?php
	$Host = "******";
	$User = "******";
	$Pass = "******";
	$DBName = "******";
	$TableName = "******";

	$Query = "SELECT * FROM $TableName WHERE Username = $Username";
	$Link = mysql_connect("$Host", "$User", "$Pass");
	mysql_select_db("$DBName");

	if (!$_POSTї'Username']) {
		echo ("Please fill out your username.<BR>");
	}
	if (!$_POSTї'Password']) {
		echo ("Please fill out your password.<BR>");
	}
	If (mysql_connect("$Host", "$User", "$Pass")) {
		print ("Yahoo!!!<BR>\n");
	}
	
if ($Username && $Password) { 
    $res = mysql_query("SELECT Username,Password FROM $TableName WHERE Username='$Username' AND Password='$Password'"); 
	$num = mysql_num_rows($res);
	if ($num != '0') { 
        $verified_user = $Username; 
        $verified_userpw = $Password;
		setcookie("Username", "$verified_user", time()+ "10000000");
		setcookie("Password", "$verified_userpw", time()+ "10000000");
		print ("You have sucessfully logged in.\n");
	} else {
		print ("Bad Username or Password.\n");
		mysql_error();
	}
}

mysql_close($Link);
?>
Thanks for any help you can give me.

This is going to hopefully be a user login system, but if any of you have ideas that would work better for this, that would be great.

Thanks,
CoW

Posted: Sat Oct 12, 2002 7:45 pm
by volka
try

Code: Select all

$Query = "SELECT * FROM $TableName WHERE Username = $Username"; 
$Link = mysql_connect($Host, $User, $Pass) or die(mysql_error()); 
mysql_select_db($DBName) or die(mysql_error());

you are connecting the database twice

Code: Select all

$Link = mysql_connect("$Host", "$User", "$Pass");
...
If (mysql_connect("$Host", "$User", "$Pass")) {
why?

and please read Sticky: Before Post Read: Concerning Passing Variables in PHP 4.2+

Posted: Sun Oct 13, 2002 3:07 am
by Takuma
Put "ob_start()" and "ob_flush()" at the very start and the end of the script!

Posted: Sun Oct 13, 2002 4:05 am
by Coco
you cannot have ANY output before a header("Location:") tag...
that means all echos and all html tags (including <html>)
so you will need to remove the echos at the top (maybe make them if not then redirect to login statements) cos even if you fix the sql it wont work

Posted: Sun Oct 13, 2002 10:00 am
by volka
:oops: narrow minded me.
It was in 'Databases' so I gave the standard database-answer :lol:

Posted: Sun Oct 13, 2002 11:57 am
by twigletmac
An error message would be counted as output though wouldn't it? So it could still be a problem with the query.

SL-Cowsrule -> have you read this: viewtopic.php?t=511

Mac

Posted: Sun Oct 13, 2002 2:19 pm
by Coco
yah twig but the point is that even if the query worked theres output before the header :P