2012-12-03 210 views
-2

你們能幫我嗎?我仍然不明白關於警告和如何解決,雖然我看所有的解決方案警告:mysql_fetch_array():提供的參數不是一個有效的MySQL結果資源,並沒有選擇數據庫

<php 
    $hostname = "localhost"; 

    $database= "doctor"; 

    $username = "root"; 

    $password = ""; 

    $doktor = mysql_pconnect($hostname, $username, $password) or 

    trigger_error(mysql_error(),E_USER_ERROR); 

    $IdCountry = isset($_POST['IdCountry']); 

    $Country= isset($_POST['Country']); 

    $result = mysql_query("SELECT * FROM warganegara WHERE IdWarga = '$IdWarga'"); 
if(mysql_num_rows($result) >0){ 
while ($test = mysql_fetch_array($result) or die (mysql_error())){ 


} 
    if (!$result) 

    { 

    die("Error: Data not found.."); 

    } 

    $Country=$test['Country'] ; 

    if(isset($_POST['save'])) 

    { 

    $Country_save = $_POST['ctry']; 

    mysql_query("UPDATE country SET Country='$Country_save' WHERE IdCountry = '$IdCountry'") 

    or die(mysql_error()); 

    echo "Saved!"; 

    header("Location: index.php"); 

    } 

    mysql_close($doctor); 

    ?> 

的問題已經回答n感謝guys..but現在我可以編輯任何東西,因爲文本框什麼也沒有出來,雖然我點擊編輯某些國家

+0

使用[mysql_select_db($ database)](http://php.net/manual/en/function.mysql-select-db.php)函數來選擇數據庫。 –

+0

它與白頁... –

+1

[**請不要在新代碼**中使用'mysql_ *'函數](http://bit.ly/phpmsql)。他們不再被維護,[棄用過程](http://j.mp/Rj2iVR)已經開始。看到[**紅框**](http://j.mp/Te9zIL)?學習[*準備的語句*](http://j.mp/T9hLWi),並使用[PDO](http://php.net/pdo)或[MySQLi](http://php.net/ mysqli) - [這篇文章](http://j.mp/QEx8IB)將幫助你決定哪個。如果你選擇PDO,[這裏是一個很好的教程](http://j.mp/PoWehJ)。 –

回答

0

isset返回布爾值,讓你的IdCountry和像正在設置爲布爾值而不是字符串。不要對結果進行模具測試,而應該在查詢上進行,並且應該沒問題。

+0

我只是把它相同,因爲你說,但仍然相同.. –

相關問題