Need some PHP help....

Status
Not open for further replies.

bam bam

New member
Oct 9, 2007
962
11
0
I need a way to make this - Cycle Site Feed Generator

Post the data entered into a database and not a txt file like it does at the minute, here's all the code i use......

Keyword Input....

HTML:
<html>
<head>
<title>Cycle Site Feed Generator</title>
</head>
<body>
Enter your desired keywords below (one per line)... 
<br>
<form name="keywordform" action="http://www.artofbam.com/priv/somethin.php" method="POST">
<textarea rows="20" cols="20" name="keywords">
</textarea>
<br>
<input type="submit" value="Submit Keywords" >
</body>
</html>
/somethin.php.....

PHP:
<?
      if($handle = fopen('keywords.txt', 'w')){

            fwrite($handle, $_POST['keywords']);

            fclose($handle);

      }

$filename = 'keywords.txt';
$handle = fopen($filename, "rb");
$keywords = fread($handle, filesize($filename));
fclose($handle);

  //These use + to seperate keywords....

$keywords = str_replace(" ", "+", $keywords);
$keywords = explode("\n", $keywords);

foreach($keywords as $keyword)
{
  echo 'http://blogsearch.google.com/blogsearch_feeds?hl=en&q=' . $keyword . '&ie=utf-8&num=100&output=rss<br>';
  echo 'http://www.blogpulse.com/rss?query=%22' . $keyword . '%22&sort=date&operator=phrase<br>';
  echo 'http://search.live.com/feeds/results.aspx?q=' . $keyword . '&go=Search+Feeds&form=QBFR<br>';
  echo 'http://feeds.technorati.com/search/' . $keyword . '?authority=a4&language=en<br>';

}
?>
Any ideas? :bigear:
 


Have you made any attempt to put it in a database? Do you know how to access and read a database? What database engine do you intend to use?

Someone might be more kind than me, but I'm not willing to do the work for you (unless you pay me). As hint, you need to change these lines:

if($handle = fopen('keywords.txt', 'w')){
fwrite($handle, $_POST['keywords']);
fclose($handle);
}
and these lines
$filename = 'keywords.txt';
$handle = fopen($filename, "rb");
$keywords = fread($handle, filesize($filename));
fclose($handle);
With something that accesses, reads from and inserts into your favourite database.
 
Yeah i've tried looking it up, i'm a total Newb at PHP and MySQL.
I'll keep looking, thanks for the encouragement though!

I'm not going to be marketing this when its done btw, it'll be free for all and ad free.
 
First, you need to connect to your mysql server and select a database:

Code:
mysql_connect("..server..", "..username..", "..password..") 
or die("Could not connect to DB");
mysql_selectdb("..dbname..");
then, instead of this:

Code:
if($handle = fopen('keywords.txt', 'w')){
  fwrite($handle, $_POST['keywords']);
  fclose($handle);
}
use this:

Code:
$keywords = explode("\n", $_POST['keywords']);
foreach($keywords as $kw) {
  if(trim($kw) != '') mysql_query("INSERT INTO kwdata (keyword) VALUES('".mysql_real_escape($kw)."')");
}
Its just a basic example, it all depends on what do you need to do with the data in the database afterwards. Also, there should be a test if the currently entered keyword is not already stored in database (or you could store a number, how many times it has been entered etc etc etc).

 
1. Setup mysql database
2. Connect to database [mysql_connect()]
3. Query database [mysql_query()]
4. Grab results [mysql_result()]
5. Insert results [mysql_query(), again]

[NB: php commands in brackets are only one way of doing this - in many cases there are many analogous (or better) ways of doing it. Start with these and read around the PHP manual. Easy peasy.]

Essentially this is all you need to know to build a database driven site, so it's hugely advantageous to get all this under your belt. You'll be a better man for it.
 
  • Like
Reactions: bam bam
Status
Not open for further replies.