cr-ispinternet Posted June 29, 2008 Share Posted June 29, 2008 Hi All, I was wondering if any one could help me solve this problem i have with regards to a function and vars from either a database select or a top line php POST... i have the following which works great <? function telnet_commands($ip, $port, $udelay = 500000) { $ip = "0.0.0.0"; $port = "0000"; $admin_pass = "password"; // Inital Command $command = 'command here'; $output = ""; // Start of telnet connection sequence if ($fp = fsockopen($ip, $port, $errno, $errstr, 5)) { //enter password fputs($fp, "{$admin_pass}\r\n"); usleep($udelay); //enter commands fputs($fp, "{$command}\r\n"); usleep($udelay); $output .= fread($fp, 1024); usleep($udelay); echo("$command Actoined!\r"); //exit telnet fputs($fp, "exit\r\n"); return $output; } else { return "{$errstr} ({$errno})<br />\n"; } } telnet_commands(""); ?> The above does what i need it to, but i want to take it further and add the addition of selecting from a mysql database for the IP, Port and username along with commands etc etc.... if i add the mysql query inside the function it goes tits if i add it outside the function it goes tits, does any one know where its supposed to go with out having any problems??? i know this may seem vague, but all i want to do is use vars from a mysql statement in the function... Thanks for any replies Alan Link to comment https://forums.phpfreaks.com/topic/112469-echo-vars-in-function-from-mysql-statement/ Share on other sites More sharing options...
DarkWater Posted June 29, 2008 Share Posted June 29, 2008 Show some code that illustrates how you're trying to do it. Link to comment https://forums.phpfreaks.com/topic/112469-echo-vars-in-function-from-mysql-statement/#findComment-577467 Share on other sites More sharing options...
cr-ispinternet Posted June 29, 2008 Author Share Posted June 29, 2008 Hi there, This was first attempt and tried it a few other ways also like outside the function also... <? function telnet_commands($ip, $port, $udelay = 500000) { include('includes/connection.php'); // Mysql query to gain actual variables $query = "SELECT * from store_server where company_id = 'NXT15265'"; $result = mysql_db_query('jaamediaserver',$query); while($row = mysql_fetch_object($result)) { $ip = "$row->ip"; $port = "$row->port"; $admin_pass = "$row->admin_passsword"; } // Inital Command $command = 'control piggy play'; $output = ""; // Start of telnet connection sequence if ($fp = fsockopen($ip, $port, $errno, $errstr, 5)) { //enter password fputs($fp, "{$admin_pass}\r\n"); usleep($udelay); //enter commands fputs($fp, "{$command}\r\n"); usleep($udelay); $output .= fread($fp, 1024); usleep($udelay); echo("$command Actoined!\r"); //exit telnet fputs($fp, "exit\r\n"); return $output; } else { return "{$errstr} ({$errno})<br />\n"; } } telnet_commands(""); ?> Myabe i have have abrace in the worng place etc thanks for responding.. Ps im not very good with functions :-) Alan Link to comment https://forums.phpfreaks.com/topic/112469-echo-vars-in-function-from-mysql-statement/#findComment-577489 Share on other sites More sharing options...
br0ken Posted June 29, 2008 Share Posted June 29, 2008 Do you have errors turned on and if so, are any displayed? Link to comment https://forums.phpfreaks.com/topic/112469-echo-vars-in-function-from-mysql-statement/#findComment-577495 Share on other sites More sharing options...
cr-ispinternet Posted June 29, 2008 Author Share Posted June 29, 2008 Hi All, After a few hours of looking and learning, and im posting the answer for this as i hate it when you find a thread which matches your problem... They then say yeah ive fixed it and never post the solution so basically posting varibles into a function is impossible unless you define them as a global... so what i did was the following, just after your function starts you put the following global vars, and can you put all your other mysql and POST vars outside the function.... thanks to any one who replied, im glad no one gave me the answer ive l;earnt so much in the last hour :-) function telnet_commands($ip, $port, $udelay = 500000) { global $ip; global $port; global $admin_pass; global $command; Link to comment https://forums.phpfreaks.com/topic/112469-echo-vars-in-function-from-mysql-statement/#findComment-577524 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.