2013-04-12 88 views
-1
$username="N/A"; 
$password="N/A"; 
$database="N/A"; 
$host="N/A"; 
$dbConn = mysql_connect($host, $username, $password, $database) 
or die("Could not connect: " + mysql_error()); 
mysql_select_db($database, $dbConn) 
or die("Could not find database: " + mysql_error()); 


$txt = "<table align=\"center\">"; 
    $txt .= "<tr><td>KeyCode</td><td>Date</td><td>Sold</td><td>Email</td></tr>"; 
    $sql = "SELECT * FROM `benkeys` where id = 1"; 
$res = mysql_query($query, $dbConn) 
or die(mysql_error()); 
if($res && mysql_num_rows($res)) { 
} 

mysql_close($dbConn); 
     $cal = "js_del_key('".$row["keycode"]."'); return false;"; 
     $txt .= "<tr><td>".$row['keycode']."</td><td>".$row['datum']."</td>"; 
     $txt .= "<td>".$row['sold']."</td><td>".$row['email']."</td>"; 
     $txt .= "<td><input type=\"button\" name=\"del\" value=\"DELETE\" onclick=\"".$cal."\"></td></tr>"; 

    $cal = "js_add_key(); return false;"; 
    $txt .= "<tr><td><input type=\"text\" size=\"46\" id=\"nkey\" /></td><td>".date("Y-m-d")."</td>"; 
    $txt .= "<td>N</td><td>&nbsp;</td>"; 
    $txt .= "<td><input type=\"button\" name=\"addkey\" value=\"ADD NEW\" onclick=\"".$cal."\"></td></tr>"; 
    $txt .= "</table>"; 
    mysql_close($link); 
    return($txt); 

function p_adm_del_key($key) 
{ 
    $link = dbconnect(); 
    $sql = "delete from `benkeys` where `keycode`='".$key."' limit 1"; 
    mysql_query($sql); 
    mysql_close($link); 
    return(p_adm_list_keys()); 
} 
function p_adm_add_key($key) 
{ 
    $link = dbconnect(); 
    $sql = "insert into `benkeys` (`keycode`,`datum`,`sold`) values ('".$key."','".date("Y-m-d")."','N')"; 
    mysql_query($sql); 
    mysql_close($link); 
    return(p_adm_list_keys()); 
} 
function dbconnect()  
{ 
    $link = mysql_connect(DBHOST, DBUSER, DBPWD) or die ("Error: ".mysql_error()); 
    mysql_select_db(DBNAME) or die("Could not select database: ".mysql_error()); 
    return($link); 
} 
?> 

㈣看着一切多次,包括數據庫,但我似乎無法找到什麼錯了,我沒有錯誤,只是「查詢爲空」可能有人請幫助我將不勝感激感謝。Mqsql錯誤查詢爲空

我的SQL根

SELECT * 
FROM `benkeys` 
LIMIT 0 , 30 
+0

考慮不使用'mysql_ *'函數,因爲它們已被棄用。改爲使用'mysqli_ *'或'PDO'。 – Voitcus

回答

1

變化

$sql = "SELECT * FROM `benkeys` where id = 1"; 
$res = mysql_query($query, $dbConn); 

$sql = "SELECT * FROM `benkeys` where id = 1"; 
$res = mysql_query($sql, $dbConn) 
+0

現在在'where子句'中得到了這個未知列'id' –

+0

你有一個名爲id的列,在你的benkeys表中db? –

+0

不,但我很確定其被稱爲「鍵碼」 –

0

替換$ query以$ sql

$res = mysql_query($sql, $dbConn)