我剛剛開始製作網站。在註冊頁面的頂部,有一個搜索欄,您可以在其中找到現有用戶。找到並選擇用戶後,它將自動填寫註冊表單中的值。從那裏,你可以更新用戶信息。或者創建一個新用戶。出於某種原因,無論我輸入什麼值,它只會調用更新功能,而不會創建新用戶。任何幫助將不勝感激。謝謝!無法使用PHP更新MySQL中的表格
//Checks database to see if user exist by first name and last name
$check_exist ="SELECT * FROM staff WHERE firstname= '$firstname' AND lastname='$lastname'";
$exist_result = mysql_query($check_exist);
echo "TEST exist_result:" .$exist_result ."<br>";
//Updates user if user already exist
if($exist_result)
{
echo "Update function called... <br>";
for($i = 0; $exist_row = mysql_fetch_array($exist_result); $i++)
{
//get the id number
$ID = $exist_row['ID'];
}
//Updates staff table
mysql_query("UPDATE staff SET position = '$position', firstname = '$firstname', lastname = '$lastname',
address = '$address', city = '$city', state = '$state', zipcode = '$zipcode', phone = '$phone', ss = '$ss'
WHERE ID = '$ID'");
//Updates login table
mysql_query("UPDATE login SET ID = '$ID', position = '$position', username = '$username', password = '$password', email = '$email' WHERE ID = '$ID'");
}
//Registers user if user doesn't exist in database
else
{
echo "Insert function called...<br>";
//Insert Staff information
$insert_staff = "INSERT INTO staff (position, firstname, lastname,
address, city, state, zipcode, phone, ss)
VALUES ('$position','$firstname','$lastname','$address','$city',
'$state','$zipcode','$phone','$ss')";
mysql_query($insert_staff);
//This gets the newly created unqiue ID number from staff and insert it into login table
$get_id = mysql_query("SELECT * FROM staff
WHERE firstname='$firstname' AND lastname ='$lastname'");
$login_row = mysql_fetch_array($get_id);
$eID = $login_row['ID'];
//Insert Login information
$query2 = "INSERT INTO login (ID, position, username, password, email)
VALUES ('$eID', '$position','$username','$password','$email')";
mysql_query($query2);
}
這裏的錯誤我得到:
Notice: Use of undefined constant myusername - assumed 'myusername' in /Applications/MAMP/htdocs/cms/manager/insertReg.php on line 9
Deprecated: Function session_is_registered() is deprecated in /Applications/MAMP/htdocs/cms/manager/insertReg.php on line 9
Notice: A session had already been started - ignoring session_start() in /Applications/MAMP/htdocs/CMS/connectdb.php on line 8
TEST first name:ksdfjlsdkjf3242
TEST last name:lkjdslfkjdslkj
TEST exist_result:Resource id #5
Update function called...
Notice: Undefined variable: ID in /Applications/MAMP/htdocs/cms/manager/insertReg.php on line 55
Notice: Undefined variable: ID in /Applications/MAMP/htdocs/cms/manager/insertReg.php on line 58
Notice: Undefined variable: ID in /Applications/MAMP/htdocs/cms/manager/insertReg.php on line 59
記住(特別是在執行更新和刪除時)過濾和轉義用戶提供的任何數據,包括post,get,server,session和cookie數據以從SQL注入中進行自我投影。 –