我有这个代码来选择'求职者'表中的所有字段,并且它应该通过将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