variable value is not being pushed to the next page

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ridwan
Forum Commoner
Posts: 55
Joined: Thu Aug 22, 2002 3:15 am

variable value is not being pushed to the next page

Post 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
?>
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post 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
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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
ridwan
Forum Commoner
Posts: 55
Joined: Thu Aug 22, 2002 3:15 am

thanx

Post by ridwan »

thanks
Post Reply