Php mysql fetch problem

You’re welcome.

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);
		}

?>

[HIGHLIGHT="XHTML 1.0 Transitional//EN Code"]

<form action=“genPdf.php” method=“post” class=“genPdf”>
<label for=“email” class=“genPdf”>Email: </label><br />
<input type=“text” name=“email” class=“genPdf” title=“Enter user’s email here” />

	&lt;input type="submit" name="submit" value="Enter" class="genPdf" /&gt;
	&lt;/form&gt;


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.

No thanks, I have too many other things to do right now.

What you can do though is to work out what parts of the switch statement are being used when the error is being experienced.

Then you can var_dump $urow to find out what data is being retrieved

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>"; 

hmmm ok.

Thanx for the suggestion.

Well I think I should get my hand dirty with mysql left join for some time, and if wont work then take that matter to the right forum.

Morning is good. Sunday is today. Going good. :wink:

Jake

I’ve posted my current code on post no. #18.

That code is my current code. I tried to with switch case statement for sometime but it was not working either.

So then revert back to if else condition. and that is on post no. #18.

While $_POST[‘username’] && $_SESSION are working, only $_POST[‘email’] is not working.

's ok. And it looks like Jake has a good solution there for you.

Jake

Same problem with your code too.

$_POST[‘email’] not working.

Or else all are fine.

Well, do some debugging then! :lol: We aren’t here to do your work for you.

Off Topic:

I would normally have more patience and be more helpful, but it’s nearly 5am here. Bed time I think!

Yupp he has helped me before in this code too…

Hope so now my code would be working. :slight_smile:

yeah now I’m doing that only

well u sleep well and good morning or good night what to say ? as u are off to sleep. :lol:

If your wanting to get the info from all three tables, why not use a single query:

SELECT
    users.*
FROM
    users
INNER JOIN
    userinfo AS u_info
ON
    users.id = u_info.uid
LEFT OUTER JOIN
    employer
ON
    Users.id = employer.uid

That will get the info from the three tables

Thanx Phoenix.

Now all things are working fine. Even there is no need to use any php conditional statement too. yuhoo… :Partydude:

Thanx Jake, Anthony, Paul and Phoenix

My code is working fine now.

The only problem was that $_POST[‘username’] was always set so I added just a check to whether $_POST[‘username’] is not empty.

And now it is working fine.