Jump to content

problem with my function


pouncer

Recommended Posts

Index.php:

 

<?
require_once("Database.php");
require_once("Functions.php");
   
   	$db = new Database();
   	$db->Connect();
?>

<form id="form1" name="form1" method="post" action="">
  <label>RSS Feed link: 
  <input name="txtRSS" type="text" id="txtRSS" size="70" />
  </label>
  <label>
  <input name="add" type="submit" id="add" value="Insert RSS feed into database" />
  </label>
</form>

<p> </p>
<p>Current RSS links in the database:</p>
<p>You currently have 0 links stored in the database! </p>

<?
if (isset($_POST['add'])) {
	$rsslink = $_POST['txtRSS'];

	if ($rsslink == "") echo "You didn't specify and link to add.";

	else {
		if ($rssExists($rsslink)) echo "That RSS link is already in the database.";

		else echo "good to go";
	}
}
?>

 

Functions.php:

 

<?
$table = "rss_links";

function rssExists($link) {

	$check_link = mysql_query("SELECT * FROM $table where rsslink='$link'");
	$rows = mysql_num_rows($check_link);

	if ($rows == 1) return true;

	else return false;
}


?>

 

When it's trying to check if the link is already in the database table it givres me this error:

 

Fatal error: Function name must be a string in /dir/index.php on line 29

 

Line 29 is

if ($rssExists($rsslink)) echo "That RSS link is already in the database.";

 

Can anyone see whats wrong?

Link to comment
https://forums.phpfreaks.com/topic/152795-problem-with-my-function/
Share on other sites

Ok thanks I removed the $ from the front of the function call.

 

but now i get th:

 

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /dir/Functions.php on line 10

good to go

 

Notice that I do get the 'goof to go' echo though, but why the warning?

 

line 10 in Functions.php is $rows = mysql_num_rows($check_link);

Ok problem seems to be with the table name

 

$rss_table = "rss_links";

function rssExists($link) {

	$check_link = mysql_query("SELECT * FROM `$rss_table` where rsslink='$link'") 
	or die("Query error: <b>". mysql_error());

	$rows = mysql_num_rows($check_link);

	if ($rows == 1) return true;

	else return false;
}

 

Query error: Incorrect table name ''

 

it doesnt recognise the variable table, why is this?

but i want to make $rss_table a global variable so i can use it anywhere in any pages that 'include functions.php', is this possible?

absolutely .. in this case, just add it to your function:

 

function rssExists($link, $rss_table)

 

now you can use it within your function.

so i can use them across other pages too

 

To use a value across pages, you need to include it. To use a variable across pages, you need to use session variables.

 

If you have variables and functions that always go together, you should be using a Class.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.