confusing problem ... look within

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
WebMonkey
Forum Newbie
Posts: 19
Joined: Tue May 11, 2004 1:43 pm

confusing problem ... look within

Post by WebMonkey »

Code: Select all

//user admin swtich
If ($_SESSIONї'rank'] == "admin"){
   $reference = $_SESSIONї'adminvalue'];
         } else {
             $reference = $_SESSIONї'userref'];
}

//debugging test
if ($reference == 572015935){
   echo "correct match";
         } else { 
              echo "match failure";
}

//mysql connection script left out only in this example


//result test
$result = mysql_query("SELECT * FROM messages WHERE messref='$reference'",$MySQLdb);

if ($result){
   echo "you have records";
       } else {
          echo "no records";
}

//outputs

// useradmin switch
// in both cases places the value 572015935 into $reference

//debug test
//in both cases outputs correct match

// result test
// admin = no records
// user = you have records
Why when reference seems to be identical in both situations does the SQL clause work in one occasion and not the other? only difference between the 2 is that one originated from a text box (adminvalue) and (userref) was output from another SQL query earlier on
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post by launchcode »

Place the value in quotes for the comparison - the number is too large for an integer and is being converted to a float which will mess your SQL query up.

if ($reference == '572015935'){

Also what type of SQL field is messref in your table?
WebMonkey
Forum Newbie
Posts: 19
Joined: Tue May 11, 2004 1:43 pm

Post by WebMonkey »

thanks for the help

well userref is a varchar(40) ... your idea sounds possible but now that i have been playing with it ... the queries have stopped working all together ... what was once working seems not working anymore its becoming worse off
User avatar
launchcode
Forum Contributor
Posts: 401
Joined: Tue May 11, 2004 7:32 pm
Location: UK
Contact:

Post by launchcode »

Well post your newly modified code then - the suggestion I made would not effect the rest of the queries.
Post Reply