2016-10-18 57 views
0

我在更新數據到數據庫中的數據庫時遇到問題我查看是否有任何錯誤,但一切看起來都沒問題我以前的代碼沒有錯我已經使用舊代碼使用$ _POST測試過它知道這是不推薦,這就是爲什麼我嘗試這個新的代碼,請幫助數據不會在數據庫中更新

<?php 
 
$con=mysqli_connect("localhost", "", "Password", ""); 
 

 
// Check connection 
 
if (mysqli_connect_errno()) { 
 
    echo "Failed to connect to MySQL: " . mysqli_connect_error(); 
 
} 
 

 
// escape variables for security 
 

 
     $xskids = mysqli_real_escape_string($con, $_POST['xskids']); 
 
    $skids = mysqli_real_escape_string($con, $_POST['skids']); 
 

 
$sql="UPDATE shirt1_table SET xskids = '$xskids', skids = '$xskids' WHERE email = '$email'"; 
 

 
if (!mysqli_query($con,$sql)) { 
 
    die('Error: ' . mysqli_error($con)); 
 
} 
 
echo "record added"; 
 

 
mysqli_close($con); 
 
?>

OLD CODE

<?php 
 
require_once("configur.php"); 
 
\t 
 
$mysqli = new mysqli("localhost", "", ""); 
 
    
 
$query='UPDATE shirt1_table SET xskids="'.$_POST[xskids].'",skids="'.$_POST[skids].'" 
 
WHERE email= "'.$_SESSION['email'].'"'; 
 

 
if ($mysqli->query($query) === TRUE) { 
 
\t 
 

 
    echo "success"; 
 

 
} else { 
 
    echo "Error updating record: " . $conn->error; 
 
} 
 

 
$mysqli->close(); 
 
    
 
?>

+0

你的數據庫連接是否工作? – rbr94

+0

是的它確實,但因爲這是新的代碼,我不知道它是否影響它不適,上傳我的舊代碼 –

+0

你檢查你的PHP錯誤日誌或代碼輸出任何錯誤? – rbr94

回答

1

您在新代碼中沒有設置$email。試着這樣做:

$xskids = mysqli_real_escape_string($con, $_POST['xskids']); 
$skids = mysqli_real_escape_string($con, $_POST['skids']); 
$email = mysqli_real_escape_string($con, $_SESSION['email']); 

$sql="UPDATE shirt1_table SET xskids = '$xskids', skids = '$xskids' WHERE email = '$email'"; 
+0

謝謝你的作品,我認爲這是沒有必要的,因爲我不張貼到表 –

+0

@ghostbaby沒問題 – rbr94