Jump to content

IanS

New Members
  • Posts

    3
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

IanS's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Sorry, i wasnt literal enough. The code i was giving was an example. 1. php.ini display_errors = On error_reporting = E_ALL $ ~E_NOTICE 2. more Code ** test.php ** <?PHP include ("./sqlfunctions.php"); // contains user function called sql, for mysql functions $selected_id='1'; $statment = "select * from debtors where Ourref=$selected_id"; $res = sql($statment); $row = mysql_fetch_array($res); . . ?> ** sqlfunctions.php ** <?PHP function sql($statment,$assoc=1) {   $dbhost= "host";   $dbuser= "user";   $dbpass= "pass";   $dbname= "dbase";   echo $statment; // displays correct contents of $statment eg: "select * from .... " etc.   if(!mysql_connect($dbhost,$dbuser,$dbpass))   {     echo Stylesheet() . "\n\n<div class=Error>";     echo $Translation["error:"] . mysql_error();     echo "</div>";     exit;   }   echo $statment; // display empty (or null?) contents of $statment eg: "". . . . . ?> Summary ======= The first echo displays the correct contents. The second echo shows nothing. The sql statment mysql_connect runs and connects. The if(!mysql_connect(xxx)) { failure code } failure code isnt actioned, therefore no other functions or actions are taken before the second echo $statment; To me (limited expertise excepted), The $statment variable seems to be reset by the mysql_connect function call. I've even used other variable names eg:$statmentxc and get the same result. This is sending me bonkers!! There has to be a simple solution to this. Regards Ian.
  2. Looked at my PHPinfo and BOTH mysql and mysqli are enabled. If i take the php mysql_* code out of the Included PHP file and out of the function, and just use it directlyas inline code, it all works fine. SO, That leads me to believe the actual syntax of the Mysql code is fine. It something to do with the Include process, the Function process, or maybe .ini file or some combination. Just dont know? Any more ideas? Is what im doing - SQL code within user function within Include file - all OK in principle? Ian
  3. HI, Im new to PHP - so still getting a grip on hopefully whats obvious to someone, although having read the manual - not obvious to me. I am modifying an existing script and it just dont seem to work on my machine. a WAMP server. Environment as follows: Apache 3.33(win32) PHP V5.04 MySQL 4.1.10a-nt-extension:mysqli ***** Test.php *** include ("./sqlfunctions.php") // have code that sets up a variable called $statment. $statment = "select * from debtors" $res = sql($statment) **** sqlfunctions.php **** function sql($statment,$assoc=1) {   echo $statment // gives me select * from debtors   // connect to DB     If (!mysql_connect(host,user,pass))     {       echo "error" . mysql_error();       exit;     } echo $statment // gives me nothing - variable contents seemed to have been cleared?? // when i try to use $statment in actual qry - i get "empty qry" error. . . . } So - any obvious mistakes here?? Thing that annoys me is that im told this style of coding works on someones production LAMP environment!! regards Ian.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.