pouncer Posted April 6, 2009 Share Posted April 6, 2009 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? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 6, 2009 Share Posted April 6, 2009 Unless you are dynamically calling a function, a $ is not used in front of a function name. Quote Link to comment Share on other sites More sharing options...
pouncer Posted April 6, 2009 Author Share Posted April 6, 2009 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); Quote Link to comment Share on other sites More sharing options...
pouncer Posted April 6, 2009 Author Share Posted April 6, 2009 oops double post Quote Link to comment Share on other sites More sharing options...
pouncer Posted April 6, 2009 Author Share Posted April 6, 2009 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? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 6, 2009 Share Posted April 6, 2009 You need to pass the $rss_table variable as a parameter in the function call, the same as what you are doing with the $link variable. Quote Link to comment Share on other sites More sharing options...
pouncer Posted April 6, 2009 Author Share Posted April 6, 2009 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? Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted April 6, 2009 Share Posted April 6, 2009 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. Quote Link to comment Share on other sites More sharing options...
pouncer Posted April 6, 2009 Author Share Posted April 6, 2009 how do i make variables global then, so i can use them across other pages too? and also how can i do it so i dnt have to include it in my function Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted April 6, 2009 Share Posted April 6, 2009 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.