plodos Posted June 4, 2008 Share Posted June 4, 2008 $sql="SELECT d_name,password FROM doctor WHERE d_name='$myusername' and password='$mypassword'"; $result=mysql_query($sql); // Mysql_num_row is counting table row $count=mysql_num_rows($result); // If result matched table row must be 1 row if($count==1){ $_SESSION['loggedInD'] = true; $_SESSION['UserName'] = $myusername; $_SESSION['PassWord'] = $mypassword; header('location:doctor.php?'.SID.''); } There is a problem <? session_start(); include("dbconfig.php"); if (!$_SESSION['loggedInD']) { header("location:login.php"); die (); } else { $dd_name=$_SESSION['PassWord']; $sql = "select d_id from doctor where password like '%$dd_name%' "; echo mysql_query($sql); echo "\n"; echo $sql; } output is like that Resource id #5 select d_id from doctor where password like '%lukeW%' but LUKE ID is 1... $dd_name=$_SESSION['PassWord']; //this is working.. but there is a problem here, $sql = "select d_id from doctor where password like '%$dd_name%' "; im my opinion, we can use the session variables in the SQL querys.. What can be the error? Link to comment https://forums.phpfreaks.com/topic/108766-simple-session-problem/ Share on other sites More sharing options...
DarkWater Posted June 4, 2008 Share Posted June 4, 2008 Because you're echoing the query results instead of assigning it to a var. MySQL returns a result resource. Basically, don't do: echo mysql_query($sql); Link to comment https://forums.phpfreaks.com/topic/108766-simple-session-problem/#findComment-557950 Share on other sites More sharing options...
plodos Posted June 4, 2008 Author Share Posted June 4, 2008 sorry but i didnt understand the solution way? $dd_name=$_SESSION['PassWord']; $sql = "select d_name from doctor where password='$dd_name' "; $id = mysql_query($sql); echo $id; $dd_name=$_SESSION['PassWord']; $sql = "select d_id from doctor where password='$dd_name' "; $id = mysql_query($sql); echo $id; if I write like that....Output is only Resource id #4 What must I write for see the true result...?? Link to comment https://forums.phpfreaks.com/topic/108766-simple-session-problem/#findComment-557955 Share on other sites More sharing options...
discomatt Posted June 4, 2008 Share Posted June 4, 2008 You need to FETCH the result out of the resource, using one of these mysql_result() mysql_fetch_row() mysql_fetch_array() mysql_fetch_assoc() mysql_fetch_object() Link to comment https://forums.phpfreaks.com/topic/108766-simple-session-problem/#findComment-557958 Share on other sites More sharing options...
DarkWater Posted June 4, 2008 Share Posted June 4, 2008 $id = mysql_query($sql); $result = mysql_fetch_assoc($id); foreach ($result as $k=>$v) { echo "$k - $v <br />"; } Link to comment https://forums.phpfreaks.com/topic/108766-simple-session-problem/#findComment-557959 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.