Jump to content

pouncer

Members
  • Posts

    324
  • Joined

  • Last visited

    Never

Posts posted by pouncer

  1. The html form is built dynamically.

     

    		<form method ='post' action='index.php' name='rss_record'>
    		<input name='txtRSS_15' type='text' id='txtRSS' size='70' value='http://slashdot.org/rss/slashdot.rss'/>
    		<input name='update' type='submit' value='Update'/>
    
    		<input name='delete' type='submit' value='Delete'/>
    		<input name='view_rss' type='submit' value='View'/>
    		<input type='hidden' name='rss_id' value='15'>
    		</form>
    
    

  2. for e.g whats the difference between

     

    @mysql_insert and

    mysql_insert

    and for e.g

     

    	if (!$rss_data = @file_get_contents($link)) {
            	echo "Sorry, no RSS feed was found at <b>$link</b>";
        	}
    

     

    when i removed the @ from t@file_get_contents the page threw an error. but when i remove the @ from mysql_insert - no error?

  3. if (isset($_POST['update'])) {
    	$rss_id = $_POST['rss_id'];
    	$link = $_POST["txtRSS_" . $rss_id];
    
    	updateLink($rss_table, $rss_id, $link);
    }
    
    elseif (isset($_POST['delete'])) {
    	$rss_id = $_POST['rss_id'];
    
    	deleteLink($rss_table, $rss_id);
    }
    
    elseif (isset($_POST['view_rss'])) {
    	$rss_id = $_POST['rss_id'];
    	$link = $_POST["txtRSS_" . $rss_id];
    
    	viewRSS($link);
    }
    

     

    It's just if statements, but the contents of some of them are the same like the $rss_id variables.

     

  4. /*
     * Check if an RSS Feed link already exists in the database.
     */
    function rssExists($link, $rss_table) {
    
    	$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;
    }
    

     

    Is it possible to do it without using a query?

  5. I've got this code at the to of my index.php

     

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

     

    The Connect() method is just the mysql_connect(...) stuff.

     

    So everytime I refresh my index.php, is my web app always executing the mysql_connect?? is there a better way to do it so it just connects once when i open the index.php and not again and again...

  6.     		foreach ($rss_xml->channel->item as $item) {
            		$item_title = $item->title;
            		$item_link = $item->link;
            		$item_description = $item->description;
            		
    			echo "
    			<h3><a href='$item_link'>$item_title</a></h3>
    			<p>$item_description</p>
    			<p><a href='$item_link'>Continue reading $item_title</a></p>
    			\n";
            	}
    
    	foreach ($rss_xml->item as $item) {
            		$item_title = $item->title;
            		$item_link = $item->link;
            		$item_description = $item->description;
            		
    			echo "
    			<h3><a href='$item_link'>$item_title</a></h3>
    			<p>$item_description</p>
    			<p><a href='$item_link'>Continue reading $item_title</a></p>
    			\n";
            	}
    

     

    the only thing that is different is the 'foreach' lines

     

    foreach ($rss_xml->channel->item as $item)

    foreach ($rss_xml->item as $item)

     

    but the stuff inside it is the same. so is there a way to cut down the amount of duplicated code?

  7. view_rss.php

     

    <?
    
    $rss_url = "http://www.php.net/news.rss";
        if (!$rss_data = @file_get_contents($rss_url)) {
            echo "<p>No RSS found at $rss_url</p><p>Hmmm thats not meant to happen. RSS Fail!</p>";
        } else {
    
        $rss_xml = SimpleXML_Load_String($rss_data);
    
        $channel_title = $rss_xml->channel->title;
        $channel_link = $rss_xml->channel->link;
    
        foreach ($rss_xml->channel->item as $item) {
            $item_title = $item->title;
            $item_link = $item->link;
            $item_description = $item->description;
            echo "<h3><a href=\"$item_link\">$item_title</a></h3><p>$item_description</p><p class=\"text_right\"><a href=\"$item_link\">Continue reading  $item_title</a></p>\n";
            }
        }
    ?>
    

     

    Doesn't seem to display nothing for me. but when i try another rss link like

     

    $rss_url = "http://www.shanedj.com/blog/feed/rss/";

     

     

    then it works fine, any ideas whats going wrong guys?

  8. 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?

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

  10. 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?

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