Jump to content

if else is driving me INSANE!


dreamwest

Recommended Posts

I can tget this if else to work....and its driving me insane!

 

if (isset($_COOKIE['autoplay'])){
echo "";
}else{
echo "<a href=\"javascript: set_cookie('autoplay', 'on');\">Turn Autoplay ON</a><br>Plays Videos Automatically<br><hr>";
}
if  ($_COOKIE['autoplay'] === 'on'){ 
echo "<a href=\"javascript: set_cookie('autoplay', 'off');\">Turn Autoplay OFF</a><br>Play videos when "Play" is clicked<br><hr>";
}elseif ($_COOKIE['autoplay'] === 'off'){
echo "<a href=\"javascript: set_cookie('autoplay', 'on');\">Turn Autoplay ON</a><br>Plays Videos Automatically<br><hr>";
}

Link to comment
https://forums.phpfreaks.com/topic/141927-if-else-is-driving-me-insane/
Share on other sites

line 10.. (point 2 "PLAY")

	echo "<a href=\"javascript: set_cookie('autoplay', 'off');\">Turn Autoplay OFF</a><br>Play videos when "Play" is clicked<br><hr>";

u should type

echo "<a href=\"javascript: set_cookie('autoplay', 'off');\">Turn Autoplay OFF</a><br>Play videos when \"Play\" is clicked<br><hr>";

and the repair are

<?
if (isset($_COOKIE['autoplay']))
{
echo "";
}else{ //if (isset($_COOKIE['autoplay']))
echo "<a href=\"javascript: set_cookie('autoplay', 'on');\">Turn Autoplay ON</a><br>Plays Videos Automatically<br><hr>";
}//else if (isset($_COOKIE['autoplay']))

if  ($_COOKIE['autoplay'] === 'on'){
echo "<a href=\"javascript: set_cookie('autoplay', 'off');\">Turn Autoplay OFF</a><br>Play videos when \"Play\" is clicked<br><hr>";
}elseif ($_COOKIE['autoplay'] === 'off'){ //if  ($_COOKIE['autoplay'] === 'on'){
echo "<a href=\"javascript: set_cookie('autoplay', 'on');\">Turn Autoplay ON</a><br>Plays Videos Automatically<br><hr>";
}//elseif ($_COOKIE['autoplay'] === 'off')
?>

Your logic makes no sense...

 

You first test if $_COOKIE['autoplay'] is set and if it is you echo nothing, then further down you ask if $_COOKIE['autoplay'] equals on or $_COOKIE['autoplay'] equals off echo some data. Wouldn't it be better to enclose those two if(s) on or off in the if ISSET $_COOKIE['autoplay']!

line 10.. (point 2 "PLAY")

	echo "<a href=\"javascript: set_cookie('autoplay', 'off');\">Turn Autoplay OFF</a><br>Play videos when "Play" is clicked<br><hr>";

u should type

echo "<a href=\"javascript: set_cookie('autoplay', 'off');\">Turn Autoplay OFF</a><br>Play videos when \"Play\" is clicked<br><hr>";

and the repair are

<?
if (isset($_COOKIE['autoplay']))
{
echo "";
}else{ //if (isset($_COOKIE['autoplay']))
echo "<a href=\"javascript: set_cookie('autoplay', 'on');\">Turn Autoplay ON</a><br>Plays Videos Automatically<br><hr>";
}//else if (isset($_COOKIE['autoplay']))

if  ($_COOKIE['autoplay'] === 'on'){
echo "<a href=\"javascript: set_cookie('autoplay', 'off');\">Turn Autoplay OFF</a><br>Play videos when \"Play\" is clicked<br><hr>";
}elseif ($_COOKIE['autoplay'] === 'off'){ //if  ($_COOKIE['autoplay'] === 'on'){
echo "<a href=\"javascript: set_cookie('autoplay', 'on');\">Turn Autoplay ON</a><br>Plays Videos Automatically<br><hr>";
}//elseif ($_COOKIE['autoplay'] === 'off')
?>

 

WHOOHOO!! Works ....Thanks

 

Your logic makes no sense...

 

You first test if $_COOKIE['autoplay'] is set and if it is you echo nothing, then further down you ask if $_COOKIE['autoplay'] equals on or $_COOKIE['autoplay'] equals off echo some data. Wouldn't it be better to enclose those two if(s) on or off in the if ISSET $_COOKIE['autoplay']!

 

The first "if $_COOKIE['autoplay']" is for when theres no cookie, the rest of the script is for when they have a cookie either on or off.

 

But i can see your point..

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.