我已经正确添加了mysql数据库,在创建之后,我收到如下错误消息:
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\bcm\index.php on line 20
我的代码是:
<?php
/*
*
* Create Download Link
* Jaocb Wyke
* jacob@frozensheep.com
*
*/
//connect to the DB
$resDB = mysql_connect("localhost", "", "");
mysql_select_db("bedsitedownload", $resDB);
function createKey(){
//create a random key
$strKey = md5(microtime());
//check to make sure this key isnt already in use
$resCheck = mysql_query("SELECT count(*) FROM downloads WHERE downloadkey = '{$strKey}' LIMIT 1");
$arrCheck = mysql_fetch_assoc($resCheck);
if($arrCheck['count(*)']){
//key already in use
return createKey();
}else{
//key is OK
return $strKey;
}
}
//get a unique download key
$strKey = createKey();
//insert the download record into the database
mysql_query("INSERT INTO downloads (downloadkey, file, expires) VALUES ('{$strKey}', 'onetimedownload.zip', '".(time()+(60*60*24*7))."')");
?>
如何解决这个mysql_fetch_assoc()问题?