Yes, we get that issue a lot here, especially too with mod_rewrite issues which really need to be in the Apache Configuration forum. Grr!
I suggest that you start a new thread on the mysql forum for any issues that relate directly to MySQL code. They tend to become upset over there when php code becomes involved.
Yupp this is the only problem, my $uid is empty, dunno how, while if I try to slice this code and test on another sheet, then it is working fine, only not working with conditional statement.
Here is my standalone test script which is working just fine.
if(isset($_POST['email']))
{
require_once "includes/database.php";
$email = $_POST['email'];
$usql = "select id from users where email='$email'";
$ures = query($usql);
$urow = mysql_fetch_assoc($ures);
$uid = $urow['id'];
//echo $uid;
$sql = "select * from users u INNER JOIN userinfo ui ON u.id = ui.uid
WHERE u.id=$uid";
$res = query($sql);
$row = mysql_fetch_assoc($res);
print_r($row);
}
?>
So it has only problem with conditional statement as far as I can see. So any help regarding this would be really helpful to me.
>
$uid is obtained from a session variable called [FONT="Courier New"]$_SESSION['USER_ID'][/FONT]
[b]Action[/b]
You need to investigate why there is no user id in the session variable.
Well $_SESSION variable is not empty.
Here $_POST variable is set, so session variable wont get into picture.
But if I wont use $_POST variable then $_SESSION variable is working fine.
If u wanna I can give u the link with username and password to check and see yourself.
As I said earlier, isset($_POST) will always be true.
You need to see if $_POST[‘username’] exists before overriding the login. That’s why no session ID exists, your page will always see that $_POST exists (regardless of whether a post was sent - $_POST is an empty array in that case, but still set) and try to override information.
The switch statement is also wrong. $_POST is an array, so putting that as the switch and checking cases of keys, it makes no sense.
session_start();
require_once "includes/database.php";
if(array_key_exists('username', $_POST)){
$user = $_POST['username'];
$usql = "select id from users where username='$user'";
$ures = query($usql);
$urow = mysql_fetch_assoc($ures);
$uid = $urow['id'];
}else if(array_key_exists('email', $_POST)){
$email = $_POST['email'];
$usql = "select id from users where email='$email'";
$ures = query($usql);
$urow = mysql_fetch_assoc($ures);
$uid = $urow['id'];
}else{
$uid = $_SESSION['USER_ID'];
$user = $_SESSION['USER_NAME'];
}
$sql = "select * from users u INNER JOIN userinfo ui ON u.id = ui.uid WHERE u.id=$uid";
$res = query($sql);
$row = mysql_fetch_assoc($res);
echo "<pre>";
print_r($row);
echo "</pre>";