2011-07-10 146 views
0

你好,請你告訴我的代碼有什麼問題。我不知道我的代碼有什麼問題,它顯示沒有錯誤,也沒有result.I在我的數據庫(mysql)中創建了兩個表一個數據庫用於用戶詳細信息,另一個用於保存用戶的評論和文件。會話和登錄phpmysql幫助

<?php 

session_start(); 

$firstname= $_SESSION['SESS_FIRST_NAME']; 
    print $firstname; 
$tes=$_SESSION['SESS_MEMBER_ID']; 
print $tes; 

?> 




<?php 
// Default page display 
// Connect to the database server 
    $dbcnx = @mysql_connect('localhost', 'root', ''); 
    if (!$dbcnx) { 
    die('<p>Unable to connect to the ' . 
    'database server at this time.</p>'); 
    } 
// Select the jokes database 
if(! @mysql_select_db('tes')) { 
die('<p>Unable to locate the joke ' . 
'database at this time.</p>'); 
} 
// If a joke has been submitted, 
// add it to the database. 
if (isset($_POST['submit'])) { 

$name = $_POST['name']; 
$test = $_POST['test']; 
$sql = "INSERT INTO details SET 
userid='$tes', 
name='$name', 
test='$test', 
date=CURDATE()"; 
if (@mysql_query($sql)) { 
echo('<p>Your joke has been added.</p>'); 
} else { 
echo('<p>Error adding submitted joke: ' . 
mysql_error() . '</p>'); 
} 
} 

echo('<p> Here are all the jokes in our database: </p>'); 
// Request the text of all the jokes 
$result = @mysql_query('SELECT * FROM details where userid="1"'); 

if (!$result) { 
die('<p>Error performing query: ' .mysql_error() . '</p>'); 
    } 

// Display the text of each joke in a paragraph 
while ($row = mysql_fetch_array($result)) { 

echo('<p><big style="color: rgb(204, 0, 0);">' . $row['name'] . '&nbsp;&nbsp;</big>  <p>'); 
echo('<div style="text-align: justify;">' . $row['test'] . '&nbsp;&nbsp;</div>'); 
echo('<p><span style="font-style: italic;">' . $row['date'] . '&nbsp;&nbsp;</span>'); 


} 
// When clicked, this link will load this page 
// with the joke submission form displayed. 

?> 

回答

1

嘗試從正在使用的數據庫相關函數的開頭刪除錯誤控制運算符at at(@)。這抑制了這些功能的錯誤。另外,你有錯誤報告嗎?

ini_set('display_errors',1); 
error_reporting(E_ALL); 

您是否在頁面上看到任何文字?例如「這裏是我們數據庫中的所有笑話:」

我還看到,當您引用$ row ['name'],$ row ['test']時,您正在使用mysql_fetch_array(),就像您正在使用mysql_fetch_assoc()

+0

所以基本上一切:D – Hailwood

+0

謝謝juwin我試過你的方法,它的工作 – test