Jump to content


Photo

One of the strangest things...ever


  • Please log in to reply
17 replies to this topic

#1 johnnyk

johnnyk
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 01 July 2006 - 05:22 AM

PHP Version 5.1.4

This is weird and annoying and pissing me off.

if('2006' == '2005'){
  echo "<div class=\"class\">\n";
  echo "<h5 class=\"class\">text</h5><.br />\n";
  echo "</div>\n";
}

(I added the . to the <.br /> because this new forum is evil)

The if executes. Am I missing something obvious? Honestly, what the curse? This is the strangest PHP related problem I've ever had. Honestly, at this point if you told me it was executing because I'm not standing on my head I would believe you because I can't find any other reason.

I had another weird problem the other day. MySQL kept saying there was an error in my SQL syntax when there wasn't. I even posted it on here and someone verified it was fine with the version of MySQL I was using, but MySQL kept bitching.

So my question is, why do PHP and MySQL hate me? Or maybe my question is, why am I going crazy? This is like a PHP nightmare. Things are just going crazy for absolutely no reason at all. AHH!!!!
Rediscover the Web:
<a href="http://www.spreadfir...;t=219"></a><br />

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 01 July 2006 - 05:27 AM

Try this you dont need to back slash while using double quotes do ya lol?

if('2006' == '2005'){
   echo "<div class='class'>";
   echo "<h5 class='class'>text</h5><br>";
   echo "</div>";
}

Also when you got the " double used then in the middile you use  ' single , so double then single lol
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 01 July 2006 - 05:29 AM

yes you do need to use backslashes with double quotes, if you started out with double quotes.  but that's not the point. the point is that php is deeming that if statement true. honestly i have no clue why...
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#4 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 01 July 2006 - 05:38 AM

I tested it this way and works fine.

<?
$a="2005";
$b="2006";

if($b>$a){
   echo "<div class='class'>";
   echo "<h5 class='class'>text</h5>
";
   echo "</div>";
}
?>


this also works fine

<?
$a="2005";
$b="2006";

if($b==$a){
  echo "<div class='class'>";
  echo "<h5 class='class'>text</h5>
";
  echo "</div>";
}
?>
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#5 johnnyk

johnnyk
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 01 July 2006 - 05:39 AM

It only gets screwed up in a certain script of mine. If I isolate the if into its own php script it works fine.

Is there any possibility that somehow the rest of my script is affecting the if? Is there any possibility it's a really strange bug? Is there any possibility my host is to blame?

Something is cursed up here, but I have no idea what.

Where's the smiley for "Head is about to explode"? Damn new forum.
Rediscover the Web:
<a href="http://www.spreadfir...;t=219"></a><br />

#6 Drumminxx

Drumminxx
  • Members
  • PipPipPip
  • Advanced Member
  • 92 posts
  • LocationUSA

Posted 01 July 2006 - 05:41 AM

so if you:

if('2006' != '2005'){
  echo "<div class=\"class\">\n";
  echo "<h5 class=\"class\">text</h5><br />\n";
  echo "</div>\n";
}

does it display nothing  :o

and redarrow,

yes you do need need to escape double quotes in double quoted strings its single quoted strings that you do not need to escape double quotes.
:: gucci.com ::
:: blockbuster.com ::

--------------------

#7 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 01 July 2006 - 05:43 AM

ok thank you so try single quotes then?

cheers.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#8 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 01 July 2006 - 05:45 AM

umm.. i guess post the rest of your code that surrounds it, cuz i tried it in an isolated example for shits and grins and it worked the way it should...
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#9 johnnyk

johnnyk
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts

Posted 01 July 2006 - 05:45 AM

...um, sorry people. It actually was working fine...
I saw something coming up on the page and got confused and thought it was whats in the if...
...sorry to waste your time

I'm an idiot. But it's late at night, so you can't blame me too much.
Rediscover the Web:
<a href="http://www.spreadfir...;t=219"></a><br />

#10 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 01 July 2006 - 05:46 AM

LMAO okay  ;D
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#11 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 01 July 2006 - 05:50 AM

Crayon Violent a quick quistion how comes the code i posted in reply worked when it shouldnt as i have not added any \backslashes help lol.


I see the ansaw know its becouse the oreganal code were the class has double qoutes are there and mine are single ok

bla bla ...............
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#12 Drumminxx

Drumminxx
  • Members
  • PipPipPip
  • Advanced Member
  • 92 posts
  • LocationUSA

Posted 01 July 2006 - 05:58 AM

because you edited your post to reflect single quotes inside the double quotes, your original post would have terminated the strings and caused an error.
:: gucci.com ::
:: blockbuster.com ::

--------------------

#13 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 01 July 2006 - 05:59 AM

what he said.
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#14 Drumminxx

Drumminxx
  • Members
  • PipPipPip
  • Advanced Member
  • 92 posts
  • LocationUSA

Posted 01 July 2006 - 06:00 AM

;D
:: gucci.com ::
:: blockbuster.com ::

--------------------

#15 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 01 July 2006 - 06:03 AM

thank you.

i got told from my teacher not to use double qoutes within double qoutes

so does \escaping double qoutes work faster or is it a coding prefrence cheers.


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#16 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 01 July 2006 - 06:13 AM

it depends on the circumstance.  if you were using quotes in a normal sentence structure, for example:

The lady said, "How may I help you?"

You would want to preserve the double quotes, so you would escape them:

echo "The lady said, \"How may I help you?\"";

When dealing with variables in a string, most the time it is easer to use double quotes. Why? because if you do this:

$blah = "foobar";
echo "$blah";
echo '$blah';

The first echo will echo foobar, where as the 2nd echo will literally echo $blah.  So, if you are, for instance, building a query string, well, values require quotes around them, in order for them to be valid in mysql. well, string values do, not numerical.  But anyways, which do you think looks cleaner, this:

$sql = "update table set blah = \"".$blah."\" where id = \"". $id . "\"";

or this:

$sql = "update table set blah = '$blah' where id = '$id'";


Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#17 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 01 July 2006 - 06:22 AM


thanks for the reply.

this

$sql = "update table set blah = '$blah' where id = '$id'";
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#18 heckenschutze

heckenschutze
  • Members
  • PipPipPip
  • Advanced Member
  • 257 posts
  • LocationAustralia

Posted 01 July 2006 - 08:16 AM

You don't need to quote integers, its bad practice for a start, eg if PHP wasn't so lenient, such as C for example, trying to compare strings as you were (arrays of characters) would result in many errors.

Bad Practice:
if('2006' != '2005')
Bad Practice:
if("2006" != "2005")
Good Practice:
if(2006 != 2005)

And using quotes inside your strings will NOT slow down the parsing of your script...




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users