0

我正在尝试将访问者信息存储在数据库中。如果它不存在,我需要创建一个表,然后存储信息。但是信息没有被存储,我需要代码方面的帮助。代码 -

// visitor information
$ip = addslashes((getenv(HTTP_X_FORWARDED_FOR)) ? getenv(HTTP_X_FORWARDED_FOR) : getenv(REMOTE_ADDR));
$visitorReferrer = addslashes(( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : 'Referrer undetectable.');
$visitorBrowser = addslashes(( $_SERVER['HTTP_USER_AGENT'] ) ? $_SERVER['HTTP_USER_AGENT'] : 'Browser undetectable.');

// connect database
$con = mysql_connect("localhost","UNAME","PASS");
if (!$con)
{
  die('Could not connect: ' . mysql_error());
}

// Create table
mysql_select_db("DBNAME", $con);
$sql = "CREATE TABLE IF NOT EXISTS `logs` (
 `id` int(11) unsigned NOT NULL auto_increment,
 `ip` varchar(255) NOT NULL default '',
 `brow` varchar(255) NOT NULL default '',
 `times` varchar(500) NOT NULL default '',
  PRIMARY KEY  (`id`)
  ) ENGINE=MyISAM  DEFAULT CHARSET=utf8";

// query
mysql_query($sql,$con);
mysql_close($con);

mysql_query("INSERT INTO 'logs' (ip, ref, brow, times ) VALUES('{$ip}', '{$visitorReferrer}', '{$visitorBrowser}', now())");
mysql_close($con);

// image header to browser.
header("Content-Type: image/jpeg");

// create image and allocate colors...
$im = @imagecreate(110, 20) or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 233, 14, 91);

// IP text
imagestring($im, 1, 5, 5,  "Hello $ip !", $text_color);
imagepng($im);
imagedestroy($im);

仍然无法使用该建议,(此处为屏幕截图) http://0dae.in/cap1.png "phpadmin"

4

1 回答 1

0

您的插入语句引用了名为“ref”的列,该列不是您正在创建的表的一部分。

于 2012-10-07T07:28:01.197 回答