I'm a complete newcommer to PHP and am trying to teach myself as I go. I've looked through lots and lots of online resources, and now have some stuff that works in principal but is dying on me when I try and modify it for my own use. I have the following code:
Code: Select all
<?php
/* declare some relevant variables */
$DBhost = "localhost";
$DBuser = "username";
$DBpass = "password";
$DBName = "thisDB";
$table = "user";
import_request_variables('p', 'p_');
$link = mysql_connect($DBhost,$DBuser,$DBpass);
@mysql_select_db("$DBName") or die("Unable to select database $DBName");
$sqlquery = "SELECT * FROM $table WHERE username = $p_username AND password = $p_password";
echo $sqlquery . "<br />";
$result = mysql_query($sqlquery,$link);
if (!$result = mysql_query($sqlquery,$link))
exit("Illegal query");
$number = mysql_num_rows($result);
echo "num rows = " . $number;
?>num rows = 2
which is correct since there are currently two test records in the database.
I'm outputting the query for bugtesting, and it's appearing just fine:
SELECT * FROM user WHERE username = admin AND password = france
Yet for some reason it's still coming up as an error.
Can someone please tell me what I'm doing wrong?
Thanks.
Seona.