Jump to content

Problem with if and else statements


timmah1

Recommended Posts

I'm having problem with the if and else statements

I 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 at

Please 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

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]
ok, I got everything to work except the last if statement

Could 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
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
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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.