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? Link to comment https://forums.phpfreaks.com/topic/152795-problem-with-my-function/ 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. Link to comment https://forums.phpfreaks.com/topic/152795-problem-with-my-function/#findComment-802352 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); Link to comment https://forums.phpfreaks.com/topic/152795-problem-with-my-function/#findComment-802375 Share on other sites More sharing options...
pouncer Posted April 6, 2009 Author Share Posted April 6, 2009 oops double post Link to comment https://forums.phpfreaks.com/topic/152795-problem-with-my-function/#findComment-802377 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? Link to comment https://forums.phpfreaks.com/topic/152795-problem-with-my-function/#findComment-802389 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. Link to comment https://forums.phpfreaks.com/topic/152795-problem-with-my-function/#findComment-802393 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? Link to comment https://forums.phpfreaks.com/topic/152795-problem-with-my-function/#findComment-802404 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. Link to comment https://forums.phpfreaks.com/topic/152795-problem-with-my-function/#findComment-802409 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 Link to comment https://forums.phpfreaks.com/topic/152795-problem-with-my-function/#findComment-802467 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. Link to comment https://forums.phpfreaks.com/topic/152795-problem-with-my-function/#findComment-802472 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.