The following should work okay for you:
<?php
if ((!$username) || (!$password)) {
header("Location: blah");
exit;
}
$userc = @mysql_connect("blah", "bleck", "bleep") or die("No DB Connection");
@mysql_select_db("notgonnadoit", $userc) or die("No DB Select");
if (($userq = @mysql_query("SELECT name_first FROM guess WHERE username='$username'
AND password=PASSWORD('$password')",
$userc)) && (@mysql_num_rows($userq) == 1)) {
$namef = @mysql_result($userq, 0, 0);
echo "Welcome $namef";
} else {
header("Location: blah");
exit;
}
@mysql_close($userc);
?>
>-----Original Message-----
>From: Jeff Oien [mailto:[EMAIL PROTECTED]]
>Sent: Monday, 19 February, 2001 08:50
>To: PHP
>Subject: [PHP] Shorten this MySQL code?
>
>
>Newbie with MySQL. I have a user auth form before this
>script which asks for username and password. First
>Name and Last name are also in each record in the
>database along with username and password. When
>the user successfully logs in, I have it say, "Welcome
>name_first, you're authorized! The only way I could figure
>out how to do this is make a separate sql call to retrieve
>the first name. Can I consolidate this into one call? Thanks.
>(Based on "PHP Fast and Easy" code.)
>
><?
>
>if ((!$username) || (!$password)) {
> header("Location: blah");
> exit;
>}
>
>
>$db_name = "notgonnadoit";
>$table_name = "guess";
>
>$connection = @mysql_connect("blah", "bleck", "bleep")
> or die("Couldn't connect.");
>
>$db = mysql_select_db($db_name, $connection)
> or die("Couldn't select database.");
>
>$sql = "SELECT * FROM $table_name
> WHERE username = \"$username\"
> AND password = password(\"$password\")
> ";
>
>$result = mysql_query($sql)
> or die ("Can't execute query.");
>
>$num = mysql_numrows($result);
>
>if ($num != 0)
>
>$connection = @mysql_connect("blah", "bleck", "bleep")
> or die("Couldn't connect.");
>
>$db = mysql_select_db($db_name, $connection)
> or die("Couldn't select database.");
>
>$sql1 = "SELECT username, name_first
> FROM $table_name
> ";
>
>$result1 = @mysql_query($sql1,$connection)
> or die("Couldn't execute query.");
>
>while ($row = mysql_fetch_array($result1)) {
> $name_first = $row['name_first'];
> $username1 = $row['username'];
>
>
> if ($username1 == $username) {
> $name_first1 = $name_first;
> }
>}
>
> $msg = "<p>Welcome $name_first1, you're authorized!</p>";
>
>} else
>
> header("Location: http://www.webdesigns1.f2s.com/db/auth_login.html");
> exit;
>}
>
>?>
><html>
><head>
><title>Welcome</title>
></head>
><body bgcolor="#000000" text="#00ff00">
><? echo "$msg"; ?>
></body>
></html>
>
>--
>PHP General Mailing List (http://www.php.net/)
>To unsubscribe, e-mail: [EMAIL PROTECTED]
>For additional commands, e-mail: [EMAIL PROTECTED]
>To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]