Page 1 of 1

Global variables in PHP.

Posted: Fri Mar 18, 2005 4:24 am
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]

Posted: Fri Mar 18, 2005 5:01 am
by anjanesh
Try replacing $error with $GLOBALS['error']