I am making a PHP script that does some stuff for me, so I wont have to type out all the code over and over in my website documents.
Here is what I do:
// MyFunc.php
<?php
function DoStuff()
{
$var = 'something';
return $var;
}
?>
// index.php
<html>
<head></head>
<body>
Hi, I am currently doing <?php include "MyFunc.php"; echo DoStuff(); ?>, pretty cool, right?
</body>
</html>
However, it appears my function is not getting called. Am I doing anything wrong?
Here is my full source
//splashgen.php
<?php
$refid = $_GET['ref'];
$output = 'Company';
function GetSponsor()
{
if($refid!='')
{
$dbhost = "localhost";
$dbuser = "myuser";
$dbpass = "mypass";
$dbname = "mydb";
$sqlselect = "SELECT * FROM egbusiness_members WHERE loginid='$refid';";
$con = mysql_connect($dbhost,$dbuser,$dbpass) or die('Unable to connect to Database Server!');
mysql_select_db($dbname) or die('Could Not Select Database!');
$refid = stripslashes($refid);
$refid = mysql_real_escape_string($refid);
$result = mysql_query($sqlselect);
while ($row = mysql_fetch_array($result))
{
$output = $row['name_f']." ".$row['name_l']." (".$refid.")";
}
mysql_close($con);
}
return $output;
}
?>
/////////
// index.php
...
<font style="font-size:19px" color="#0093C4" face="Calibri"><b>
This page was brought to you by: <?php $_GET['ref']; include "../splashgen.php"; echo GetSponsor(); ?>
</b></font></div>
...
<body>
Hi, I am currently doing <?php include "MyFunc.php"; echo DoStuff(); ?>, pretty cool, right?
</body>
And make sure, your php files should start with <?php
You want DoStuff() (with parentheses) to actually call the function. Apart from that your code is fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With