PDA

View Full Version : leave a value blank?


pixelmonkey
08-10-2005, 06:31 AM
<?php
$id = $PHP_GET['id];
if ($id ="main") {
echo "html or whatever goes here\n";
}
else {
echo "something other than the above html goes here\n";
}
?>

problem is in my previous statement, if $id is blank, then it auto assumes to include "main"... but if its =something then it takes on that value... but when i run this second piece of code, it replaces $id with "main" no matter what....

thoughts?
chris<pixelmonkey>:D

Joe
08-10-2005, 06:55 AM
The PHP function empty (http://us3.php.net/manual/en/function.empty.php) should help fix that problem.

*Added* Or should help to fix the first problem ... didn't thoroughly read before I posted.

Horus_Kol
08-10-2005, 08:32 AM
if ($id ="main")

this is testing to see if $id successfully accepts the value "main"

you want:

if ($id =="main")

to test if $id already has the value "main"

RogerRamjet
08-11-2005, 10:51 PM
Yes = is the assignment operator, == the comparison

Must be a VB programmer like me, I make that mistake all the time.