PHP and new web design

crawlerbasher

Silver Level Poster
Since Final Fantasy XI is down for 1/2 the day for mataince I've decided to get of my lazy ass and work on my site that I've been neglecting.

Decided to start from scratch.

http://www.crawlerbasher.net/

Also anyone here good with PHP?

for some resion this is not working

Code:
<?php
if ($name == "" && $subject == "" && $comment == "" && $ip == "") {
			echo "I'm sorry but the name subject and comment feild are empty.\n <br /> Or we are unable to verify your IP Address.";		
			} else {
# Some random element
 }
?>

The problem is it seems to ignore the blank verable and pass it though as if there is something in the verable.

And why not add a web designing and coding section to the other topics of the forum :D
 

crawlerbasher

Silver Level Poster
nope thats not worked.
I had this problem years ago and can't rember how I solved the problem.

Well I'm not too worried at the moment.
This was a quick coding.

Plan on working on something a bit more powerful and robust at a later date.
 
Last edited:

pengipete

Rising Star
Never looked at php before so this may be complete nonsense but I just looked at some code and spotted a line that read - if (empty($var)) - don't know if that's relevent. The other thing that looked possible was Strlen()
 

Pete

Bright Spark
I don't know about PHP so much, i'm more ASP VBScript but.....

i take it && = and ? shouldn't it be OR ?

edit :

you're comparing all the fields to be empty, whereas an OR will check for one of them being empty. at least that's how it works in my asp mind.

http://www.w3schools.com/PHP/php_operators.asp
 
Last edited:

pengipete

Rising Star
I read it as conditional on all three variables being set but containing no data - if that's the intention then a logical AND would be correct.

Is the code posted running (and failing) in isolation or is that just a section from a larger chunk of code? If it's the latter, is it possible that this portion of code is actually working correctly and one or more of those strings either hasn't been defined (or was misspelled when it was) or actually does contain data?

How about a simple bug-check? Instead of just printing the text, print each variable and its contents - that should immediately confirm whether or not the IF/THEN is failing or if it is correctly giving the result - just not what you think it should be.
 

Pete

Bright Spark
if ($name == "" && $subject == "" && $comment == "" && $ip == "")

if one variable contains a value this statement will never be true, say the IP which i'm guessing is from the server variables will be pre-populated. Which is why CrawlerBasher is saying it's passing through. Test it out by setting all the variables to be "" right before the IF (it will work) and then set a value for one of them....

if you want to check for a user forgetting to enter ANY ONE of the fields you need to use OR ||
<?php
if ($name == "" || $subject == "" || $comment == "" || $ip == "") {
--- this is what i think would work best, they must enter all fields ---

to match exactly the error Crawler has "I'm sorry but the name subject and comment field are empty.\n <br /> Or we are unable to verify your IP Address." then.....
if (($name == "" && $subject == "" && $comment == "") || $ip == "") {
--- name and subject and comment must be null or the ip = null ---

hope this is right, like i say no expert in php.
 
Last edited:
Top