timmah1 Posted January 19, 2007 Share Posted January 19, 2007 I'm having problem with the if and else statementsI want to be able to have users add people to a "buddy" list.I have a field called 'status' in my database, and it either has 'pending' or 'approved' in the field.What I'm trying to do is, if you click on the button, if the buddy's name is in the database and the status says 'pending', i want it to say that, and if the buddy's name is in the database and the status says 'approved', i want it to say that, but if the buddy's name isn't in the database, i want it to display a link to add this person.This coding is by far the worst I've done, but it's where I'm atPlease don't belittle me for my coding skills ;D[code]$query = "SELECT * FROM users WHERE user_id = '{$_GET['id']}'";$mysql_result = mysql_query($query);while($myrow = mysql_fetch_assoc($mysql_result)){if ($myrow[status] = pending) {echo "You already have a pending request with this person";}else {if ($myrow[status] = approved) {echo "You are already this person's friend";}else {if ($myrow[status] = NULL) {echo "Are you sure you want to add $myrow[username] as a friend?";[/code]What's happening now is that it always displays You already have a pending request with this person, regardless of what the status is showing.Please steer me in the right direction.thanks Link to comment https://forums.phpfreaks.com/topic/34934-problem-with-if-and-else-statements/ Share on other sites More sharing options...
kenrbnsn Posted January 19, 2007 Share Posted January 19, 2007 The comparison operator for equals is "==" not "=". What you're doing is an assignment statement.Ken Link to comment https://forums.phpfreaks.com/topic/34934-problem-with-if-and-else-statements/#findComment-164743 Share on other sites More sharing options...
timmah1 Posted January 19, 2007 Author Share Posted January 19, 2007 i corrected that, but now it's just asking if I want them to be my friend, even though that friend is already in the database.How could I check two(2) values at once with the if statment?Would this be correct?[code]if ($myrow[username]==username & $myrow[status] == pending){[/code] Link to comment https://forums.phpfreaks.com/topic/34934-problem-with-if-and-else-statements/#findComment-164745 Share on other sites More sharing options...
timmah1 Posted January 20, 2007 Author Share Posted January 20, 2007 ok, I got everything to work except the last if statementCould somebody please help me with this part?[code]if ($myrow[friend_id] == NULL) {echo "Are you sure you want to add $myrow[username] as a friend?";echo "<form action=http://www.stagingtree.com/myaccount.php?op=add method=post><table width=100% border=0 cellspacing=2 cellpadding=0 class=innertable> <tr> <td> <input type=hidden name=user_id value=$myrow[user_id]><br> <input type=hidden name=username value=$myrow[username]> </td> <td> <button type=submit>Add As Friend</button></td> </tr></table></form>";}[/code]right now there's nothing in the database, so it should show the form, but it show a blank page Link to comment https://forums.phpfreaks.com/topic/34934-problem-with-if-and-else-statements/#findComment-164776 Share on other sites More sharing options...
kenrbnsn Posted January 20, 2007 Share Posted January 20, 2007 The "and" operator is "&&". If I were you, I would read the [url=http://www.php.net/manual/en/index.php]manual[/url] and get a better understanding of the PHP language before tackling more projects. If you don't understand the tools you have, you can't build a better mouse trap.Ken Link to comment https://forums.phpfreaks.com/topic/34934-problem-with-if-and-else-statements/#findComment-164778 Share on other sites More sharing options...
printf Posted January 20, 2007 Share Posted January 20, 2007 You need to learn basic scripting logic, like using (', ") to enclose comparison strings, so they are treated as what they are intended to represent. NULL and 'NULL' or "NULL" are not the same thing. If you use quotes where you should you would need to ask the questions your asking!printf Link to comment https://forums.phpfreaks.com/topic/34934-problem-with-if-and-else-statements/#findComment-164781 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.