Jump to content

[SOLVED] If Else Help


jasonhardwick

Recommended Posts

I put this bit of code together to try and call a specific button if certain criteria have been meet.

 

but my test are all returning the first "if echo" when they should show the others. any idea why?

 

 

<?php

			include "config.php";

				$user_profile=$_GET['username'];

			$sql4 = "SELECT network
        from user
WHERE uname = '$user_profile' 
	";

$result4 = mysql_query($sql4) or die (mysql_error());
$row4 = mysql_fetch_assoc($result4);
$username=$_SESSION['username'];
$user_profile=$_GET['username'];


if ($row4['network'] = $user_profile)
{
echo "<form id=\"form1\" name=\"form1\" method=\"post\" action=\"remove_network.php\">";
    echo "<input name=\"network_invite\" type=\"hidden\" id=\"network_invite\" value = \"$username\"/>";
    echo "<input name=\"invitee\" type=\"hidden\" id=\"invitee\" value = \"$user_profile\"/>";
echo "<label>"."<input type=\"submit\" name=\"button\" id=\"button\" value=\"Remove from network\" />"."</label>";
    echo "</form>";
}

else	{
if ($row4['network_invite'] = "$user_profile")
{
    echo "network invite pending";
}

else	
//if ($row4['network'] == "$user_profile")
{
echo "<form id=\"form1\" name=\"form1\" method=\"post\" action=\"add_invite.php\">";
    echo "<input name=\"network_invite\" type=\"hidden\" id=\"network_invite\" value = \"$username\"/>";
    echo "<input name=\"invitee\" type=\"hidden\" id=\"invitee\" value = \"$user_profile\"/>";
echo "<label>"."<input type=\"submit\" name=\"button\" id=\"button\" value=\"invite to network\" />"."</label>";
    echo "</form>";
}


// swhile ($row = mysql_fetch_assoc($result)) {

             }
                ?>

Link to comment
https://forums.phpfreaks.com/topic/106720-solved-if-else-help/
Share on other sites

proble lies here

if ($row4['network'] = "$user_profile")

needs to be

 

if($row4['network'] == "user_profile")

 

current code was always returning true.  Also notice you did the same thing on the next if statement.

 

if ($row4['network_invite'] = "$user_profile")

 

should be

 

if($row4['network_invite'] == "user_profile")

Link to comment
https://forums.phpfreaks.com/topic/106720-solved-if-else-help/#findComment-547074
Share on other sites

ok now i'm getting this error

"Parse error: parse error, unexpected T_ECHO, expecting ',' or ';' in /home/content/j/a/s/jasonhardwick/html/user_profile.php on line 111"

<?php

			include "config.php";

				$username=$_SESSION['username'];
				$user_profile=$_GET['username'];

			$sql4 = "SELECT *
        from user
WHERE uname = '$user_profile' 
	";

$result4 = mysql_query($sql4) or die (mysql_error());
$row4 = mysql_fetch_assoc($result4);

//$user_profile=$_GET['username'];


if($row4['network'] == "user_profile")
{
echo 
echo "<form id=\"form1\" name=\"form1\" method=\"post\" action=\"remove_network.php\">";
//
//
    echo "<input name=\"network_invite\" type=\"hidden\" id=\"network_invite\" value = \"$username\"/>"; // here is my problem line
//
//  
  echo "<input name=\"invitee\" type=\"hidden\" id=\"invitee\" value = \"$user_profile\"/>";
echo "<label>"."<input type=\"submit\" name=\"button\" id=\"button\" value=\"Remove from network\" />"."</label>";
    echo "</form>";
}

else if($row4['network_invite'] == "user_profile")
{
    echo "network invite pending";
}

else	
{
echo "<form id=\"form1\" name=\"form1\" method=\"post\" action=\"add_invite.php\">";
    echo "<input name=\"network_invite\" type=\"hidden\" id=\"network_invite\" value = \"$username\"/>";
    echo "<input name=\"invitee\" type=\"hidden\" id=\"invitee\" value = \"$user_profile\"/>";
echo "<label>"."<input type=\"submit\" name=\"button\" id=\"button\" value=\"invite to network\" />"."</label>";
    echo "</form>";
}


// swhile ($row = mysql_fetch_assoc($result)) {

             }
                ?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/106720-solved-if-else-help/#findComment-547087
Share on other sites

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.