Global variables in PHP.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
guntha
Forum Newbie
Posts: 1
Joined: Fri Mar 18, 2005 4:18 am

Global variables in PHP.

Post by guntha »

Hi all,

I am using mssql and php, so i trying to get the query result when the user enters the query and submits the execute button.

i want to differentiate the syntactically correct query and the incorrect query with different colors.

here i am posting my code for retreving the query

Code: Select all

if (-1 == $connection) 
                 $result = mssql_query($query);
               else
                 $result = mssql_query($query, $connection);               
                          if (!$result) {
  print "<p style=\"color:red;\">MS-SQL-Fehler: ".mssql_get_last_message()."</p>\n";
          $error=1;  //my changes}
what i am trying to do is intialising a global variable "$error=0" and changing it to 1 if error occurs.

when displaying i am writing like this

Code: Select all

foreach($_SESSION['history'] as $item) {
                 $item = str_replace(";","",$item);
                 if(error==0)
                 echo "<option >$item</option>";
                 else
                 echo "<option style=\"color: red;\">$item</option>";
but it does not work can you pls tell me.


feyd | Please review how to post code using

Code: Select all

and

Code: Select all

tags. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
anjanesh
DevNet Resident
Posts: 1679
Joined: Sat Dec 06, 2003 9:52 pm
Location: Mumbai, India

Post by anjanesh »

Try replacing $error with $GLOBALS['error']
Post Reply