
kanikase
Préstamo
Ómicron
Programador
Verificación en dos pasos activada
Verificado por Whatsapp
¡Ha verificado su Paypal!
Necesito ayuda con un codigo php, es para un contador de visitas por entradas, ya lo tengo configurado, pero al subirlo a mi host, y abrir el archivo me sale "Warning: mysql_close() expects parameter 1 to be resource, null given in /home/u292154245/public_html/counter.php on line 69" que esta fallando, este es el codigo que utilizo:
Lo que me dice que esta mal es esto: mysql_close($link);
Y aqui esta el archivo: http://toddescargas.com/counter.php
PHP:
<?php
//Created by Anuj Pathania --- anujpathania#gmail.com. Please Feel Free to mail me if you want any help, script has a bug or just wanna say Hi. :D
//This code is released under GPL (General Public License).
/*
You need to create a database and table to store data first, please do so by executing this command in phpmyadmin first but make sure you change database and table name --
CREATE TABLE `YOUR-COUNTER-DATABASE`.`YOUR-COUNTER-TABLE` (
`SN` BIGINT NOT NULL AUTO_INCREMENT ,
`name` VARCHAR( 1000 ) NOT NULL ,
`hit` BIGINT NOT NULL DEFAULT '1',
PRIMARY KEY ( `SN` )
) ENGINE = MYISAM
*/
Header("content-type: application/x-javascript");
$url = getenv("HTTP_REFERER");
$url = str_replace ("http://",'',$url);
$url = str_replace ("www.",'',$url);
if ($url != "")
{
$username = "xxxxxxxx_xxxxx"; // Enter Your Username and Password Here
$password = 'xxxxxxxxx'; // Enter Your Username and Password Here
$database = 'xxxxxxxxx_xxxxx'; //Enter Your Database Name Here
$table = "counter"; //Enter Your Counter Table Name Here
$link = mysql_connect('localhost', $username, $password);
if (!$link)
{
die('Could not connect: ' . mysql_error());
}
$db_selected = mysql_select_db($database, $link);
if (!$db_selected)
{
die ('Cann\'t select database : ' . mysql_error());
}
$query = "Select hit from $table where name = '$url'";
$result = mysql_query($query);
if (!$result)
{
die('Invalid query: ' . mysql_error());
}
if (mysql_affected_rows()==0)
{
$query = "Insert into counter (name) values ('$url')";
$result = mysql_query($query);
echo "document.write('1');";
if (!$result)
{
die('Invalid query: ' . mysql_error());
}
}
else
{
$hitcount = mysql_result($result, 0);
$hitcount++;
echo "document.write('$hitcount');";
$query = "Update counter set hit = $hitcount where name = '$url'";
$result = mysql_query($query);
if (!$result)
{
die('Invalid query: ' . mysql_error());
}
}
}
mysql_close($link);
?>
Lo que me dice que esta mal es esto: mysql_close($link);
Y aqui esta el archivo: http://toddescargas.com/counter.php