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
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);

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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