Simple PHP scripit.. why wont it work! :'(
Here it is.. quite simple. Taking into consideration the following example url, the paragraph below it should make sense.. :p Example url: http://www.mysite.com/out.php?url=www.yoursite.com .What I'm trying to get it to do is if the url supplied in the url exists, update the clicks column, else create a new record with the url provided in the url.. hope that makes sense! It works fine if you supply a url already in the database, but does nothing if you try to pass it a url that's not in the database. Anyway, here goes:
Code:
$select_query="SELECT url FROM $db_table WHERE url='$url'";
$update_query="UPDATE $db_table SET clicks=clicks+1 WHERE url='$url'";
$insert_query="INSERT INTO $db_table ( url,category,clicks ) values( '$url', 'regular link','1' )";
mysql_connect( $db_host, $db_user, $db_pass ) or die( "Something in the connect phase" );
mysql_select_db( $db_name ) or die( "Something in the select db phase" );
if(!($select_result=mysql_query( $select_query )))
{
if(!($insert_query=mysql_query( $insert_query )))
{
echo "The insert didnt work! :(";
}
} else
{
if(!($update_result=mysql_query( $update_query )))
{
echo "Something went wrong when trying to update the record in the database.";
}
}
mysql_close();

