我想知道如果我能讓人看看我的陳述,看看我可能會搞砸了。我已經通過回顯測試了哪些信息,並且一切看起來都正確,但我無法通過物理方式創建適當的記錄。我也沒有得到任何錯誤,並返回到表單發佈後的標題位置。表格信息不張貼
//First we make sure there are enough licenses left to add the user
$limit = "select * from organization_seats WHERE orgid=$orgid";
$orglimit = mysql_query($limit);
$licenses = $orglimit['limit'];
$count = "select count(*) from organization_users WHERE organizationid=$orgid";
if ((!$licenses < $count)) {
echo 'You have reached the number of maximum licenses for your Organization.';
} else {
//If we have licenses left, proceed to add new user
//Populate the user table
$sql = "insert into user (firstname, lastname, title, address1, address2, country, city, state, zip, phone, mobile, birthday, username, email, password) values ('$fname','$lname','$title','$address1','$address2','$country', '$city', '$state', '$zip', '$phone', '$mobile', '$bday', '$username', '$email', '$password')";
$exec = mysql_query($sql);
//Add the user to the organization
$userid = mysql_insert_id(); //call the last ID entered into the user table first
$sql2 = "insert into organization_users(organizationid, userid, active) values ('$orgid', '$userid', $)";
$exec = mysql_query($sql2);
//recall the userid
$sql3 = "select * from user where username = $username";
$exec = mysql_query($sql3);
$newuserid = $newuserselect['id'];
//Add the user to the department
$sql4 = "insert into organization_dep_users(orgid, depid, userid) values ('$orgid', '$department', '$newuserid')";
$exec = mysql_query($sql4);
if ($exec === TRUE) {
header('Location: index.php') ;
} else {
echo mysql_error();
}
}
順便說一句,我有mysql_real_escape_string附加到我所有的變量。
在新代碼[請不要使用'mysql_ *'功能(http://stackoverflow.com/q/12859942/1190388)。他們不再被維護,並[正式棄用](https://wiki.php.net/rfc/mysql_deprecation)。看到紅色框?改爲了解準備好的語句,然後使用[tag:PDO]或[tag:MySQLi]。 – hjpotter92 2013-04-11 03:59:13
哪個部分搞亂了? – 2013-04-11 04:00:42
你應該在每次調用後檢查'mysql_error()'。如果以前的通話失敗,您將聽不到它。 '$ sql3'的結果也不會被使用。 – Jim 2013-04-11 04:04:42