我有這個代碼來選擇'求職者'表中的所有字段,並且它應該通過將userType設置爲'admin'來更新'user'表,其中userID = $ userID(這個用戶ID是我數據庫中的一個用戶)。然後聲明將這些值從「求職者」表中插入到「管理員」表中,然後從「求職者」表中刪除該用戶。 sql表很好,我的語句正在將userType更改爲admin,並將用戶從'jobseeker'表中...然而,當我進入數據庫(通過phpmyadmin)時,管理員已添加了所有細節。請任何人都可以闡明爲什麼$ userData沒有從'求職者'表中傳遞用戶的詳細信息並將其插入到'管理員'表中?從一個表插入值到另一個表
下面是代碼:
<?php
include ('../database_conn.php');
$userID = $_GET['userID'];
$query = "SELECT * FROM jobseeker WHERE userID = '$userID'";
$result = mysql_query($query);
$userData = mysql_fetch_array ($result, MYSQL_ASSOC);
$forename = $userData ['forename'];
$surname = $userData ['surname'];
$salt = $userData ['salt'];
$password = $userData ['password'];
$profilePicture = $userData ['profilePicture'];
$sQuery = "UPDATE user SET userType = 'admin' WHERE userID = '$userID'";
$rQuery = "INSERT INTO admin (userID, forename, surname, salt, password, profilePicture) VALUES ('$userID', '$forename', '$surname', '$salt', '$password', '$profilePicture')";
$pQuery = "DELETE FROM jobseeker WHERE userID = '$userID'";
mysql_query($sQuery) or die (mysql_error());
$queryresult = mysql_query($sQuery) or die(mysql_error());
mysql_query($rQuery) or die (mysql_error());
$queryresult = mysql_query($rQuery) or die(mysql_error());
mysql_query($pQuery) or die (mysql_error());
$queryresult = mysql_query($pQuery) or die(mysql_error());
mysql_close($conn);
header ('location: http://www.numyspace.co.uk/~unn_v002018/webCaseProject/index.php');
?>
M上的表的結構沿後回你的發現y userID是「'或1 = 1; - ' – 2012-02-14 23:07:54
@EugenRieck他有魔術引號。 – Petah 2012-02-14 23:12:37
在查詢和查看之前添加$ userID和$ userData的調試打印。 – alfasin 2012-02-14 23:17:28