2015-01-26 206 views
-3

Hy在那裏,我想我已經盡我所能。不知何故,我的表單不起作用。 我通過URL獲得一個ID - 我試圖用來更新MySQL表php mysql插入和更新

我使用相同的表單也輸入一個新的記錄,沒有問題。但更新它根本不起作用。

if (true !=$fehler) 
{ 
if ($clientid == 'new') 
    { 
     $qy = 'INSERT INTO tbl_clientdb (
       clientid, 
       c_update, 
       c_Uupdate, 
       c_Gender, 
       c_IDNumber, 
       c_Name, 
       c_Firstname, 
       c_Middlename, 
       c_idCity, 
       c_idCountry, 
       c_idLanguage, 
       c_Phone, 
       c_Cellphone, 
       c_Email, 
       c_Note, 
       c_idCompany 
       ) 
       VALUES (
       NULL, 
       NOW(), 
       "'.$c_Uupdate.'", 
       "'.$c_Gender.'", 
       "'.$c_IDNumber.'", 
       "'.$c_Name.'", 
       "'.$c_Firstname.'", 
       "'.$c_Middlename.'", 
       "'.$c_idCity.'", 
       "'.$c_idCountry.'", 
       "'.$c_idLanguage.'", 
       "'.$c_Phone.'", 
       "'.$c_Cellphone.'", 
       "'.$c_Email.'", 
       "'.$c_Note.'", 
       "'.$c_idCompany.'" 
       )'; 
    } else { 
$qy = 'UPDATE 
      tbl_clientdb 
     SET 
      c_update  = NOW(), 
      c_Uupdate  = "'.$c_Uupdate.'", 
      c_Gender  = "'.$c_Gender.'", 
      c_IDNumber  = "'.$c_IDNumber.'", 
      c_Name   = "'.$c_Name.'", 
      c_Firstname  = "'.$c_Firstname.'", 
      c_Middlename = "'.$c_Middlename.'", 
      c_idCity  = "'.$c_idCity.'", 
      c_idCountry  = "'.$c_idCountry.'", 
      c_idLanguage = "'.$c_idLanguage.'", 
      c_Phone   = "'.$c_Phone.'", 
      c_Cellphone  = "'.$c_Cellphone.'", 
      c_Email   = "'.$c_Email.'", 
      c_Note   = "'.$c_Note.'", 
      c_idCompany  = "'.$c_idCompany.'" 
     WHERE 
      clientid = '.$clientid.' 
     LIMIT 1'; 
} 
if ($res = mysql_query($qy)) 
    { 
     echo 'Your data has been saved successfully'; 
    } 
else 
    { 
    echo mysql_error(); 
    $meld = 'Please try again'; 
    } 
}` 

任何人都不知道什麼可能是麻煩?

thx很多任何輸入。

+2

'回聲$ query'並粘貼到phpMyAdmin的。它會給你你的錯誤。任何人都很難在這裏提供幫助,因爲沒有關於你的變量是什麼的情況。 – 2015-01-26 20:23:35

+1

_'it不工作_不是一個足夠的問題描述。 – 2015-01-26 20:23:52

+0

'mysql_'已被棄用,所以您應該使用PDO和準備好的語句。 – developerwjk 2015-01-26 20:31:48

回答

0
$qy = 'SELECT 
      clientid, 
      c_update, 
      c_Uupdate, 
      c_Gender, 
      c_IDNumber, 
      c_Name, 
      c_Firstname, 
      c_Middlename, 
      c_idCity, 
      c_idCountry, 
      c_idLanguage, 
      c_Phone, 
      c_Cellphone, 
      c_Email, 
      c_Note, 
      c_idCompany 

FROM tablename WHERE id='$id' LIMIT 1"; 
$query = mysqli_query($yourConnection, $qy) or die (mysqli_error()); 
While ($row = mysqli_fetch_array($query)) { 

/* Create a variable to hold all the data */ 

$c_update = $row['c_update']; 

/* Do same for the rest */ 
} 
Mysqli_free_result($query); 
?> 

希望這有助於