Hi,
I have a problem with my script, and I can't seem to fix it. So hopefully someone will help me![]()
Right, the script is for my search engine which launches soon.
What it does, is when a user searches for something, I want to log it in a database of all search queries, so I know what people are searching for. So, if the keywords exists, it should add one to the popularity of that keyword, otherwise, if the keyword doesn't exist, it should add a new entry with the keyword, and set the popularity as one.
You see?? Quite simple really.
Ok, so the current code is:
The error I get is "Warning: Supplied argument is not a valid MySQL result resource in C:/PROGRAMMING/eliter/kwlog.php on line 11".Code:<?php // if the keyword exists if ( isset($keyword) ) { mysql_connect("localhost", "root", ""); mysql_select_db("eliter"); $result = mysql_query("SELECT COUNT(*) FROM keywords WHERE keyword='$keyword' "); $rows = mysql_num_rows($result); if ( $rows == '0' ) { mysql_query("INSERT INTO keywords SET keywords='$keyword', popularity='1' "); echo("<font size=1 face=verdana color=c0c0c0>The new keyword has been added to the database</font>"); } else { // find the popularity of the keyword $selectpop = mysql_query("SELECT popularity FROM keywords WHERE keywords='$keyword' "); while ( $details = mysql_fetch_array($selectpop) ) { $popularity = $details["popularity"]; // new popularity = old popularity plus one $newpopularity = $popularity + 1; mysql_query("UPDATE keywords SET popularity='$newpopularity' WHERE keywords='$keyword' "); echo (" <font size=1 face=verdana color=c0c0c0> The keyword $keyword has been adjusted.</font><br> "); } } } else { echo (" <font size=1 face=verdana color=c0c0c0> There was an <b>error</b> adding the keyword into the database.</font> "); } ?>
Before I added the part where it checks if the keyword exists, it worked fine, but now it doesn't..
Could someone please help?
Cheers.
-AJ





Bookmarks