Page 1 of 1

variable value is not being pushed to the next page

Posted: Thu Nov 07, 2002 7:39 am
by ridwan
I have a value which has been set in the previous page but it is not going through:

for example I set a variable to a dynamic number which it pulls from the database but when it is supposed to be used on the next page it gets lost !

this is what it looks like:

Code: Select all

<?php
<a href="main_intro.php?id=
                                                    <? echo $row->contentid . "&pagetype=news" ?>
                                                    ">
	                                                <font color="#69B92E"><? echo nl2br(substr($row->information,0 ,70)); ?>
?>
And then on the next page it should put the number into the id variable:

Code: Select all

<?php
If ($id = '')
                            $query = "SELECT * FROM mecercontent ORDER BY date DESC";
                        Else
                            $query = "SELECT *,contentid FROM mecercontent WHERE contentid = $id ";
?>
but when i run it it gives me the following error:

Error in query: SELECT *,contentid FROM mecercontent WHERE contentid = . You have an error in your SQL syntax near '' at line 1


thanks
?>

Posted: Thu Nov 07, 2002 7:48 am
by twigletmac
In this line you are setting $id to be an empty string no matter what the value of it is initially:

Code: Select all

If ($id = '')
to compare $id to an empty string use

Code: Select all

if ($id == '')
or better yet use the empty() function:

Code: Select all

if (empty($id))
Mac

Posted: Thu Nov 07, 2002 8:02 am
by volka
as additional note:http://www.php.net/manual/en/function.empty.php
This is the opposite of (boolean) var, except that no warning is generated when the variable is not set.
so

Code: Select all

$id = 0;
if (empty($id))
	echo 'is empty';
will print is empty

thanx

Posted: Thu Nov 07, 2002 8:03 am
by ridwan
thanks