我即将制作一个复选框,将其存储在我检查的位置,但出现错误:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' Array, 5' at line 1
我现在更新了我的代码,我得到一个新的错误:
“无法添加或更新子行:外键约束失败 ( dashboard
. das_custermers_employees
, CONSTRAINT das_custermers_employees_ibfk_5
FOREIGN KEY ( das_employess_id
) REFERENCESdas_employer_roles
( id
))”
希望有人可以提供帮助...我已将所有代码放入 så 希望有人能看到问题所在
我的 HTML
<div class="contact_form_div">
<form method="post">
<?php
global $wpdb;
if (isset($_POST['add_contact_btn'])) {
mysql_query("DELETE FROM das_custermers_employees WHERE das_custermers_id = $user_custermers_id") or die(mysql_error());
if (!empty($_POST['role_checkbox']) && is_array($_POST['role_checkbox'])) {
foreach ($_POST['role_checkbox'] as $employess_roles) {
foreach ($employess_roles as $em_id ){
$employess_hidden = $_POST["employess_hidden_$em_id"];
mysql_query("INSERT INTO das_custermers_employees(das_employess_id, employees_role_id, das_custermers_id) VALUES ($employess_hidden, $em_id, $user_custermers_id) ") or die(mysql_error());
}
}
}
}
$show_employess = mysql_query("SELECT * FROM das_employess") or die(mysql_error());
while ($my_employess = mysql_fetch_array($show_employess)) {
?>
<b><? echo " " . $my_employess['first_name'] . " ";
echo $my_employess['last_name'] . " "; ?></b>
<?
$show_role = mysql_query("SELECT * FROM das_employer_roles") or die(mysql_error());
while ($my_role = mysql_fetch_array($show_role)) {
?>
<input type="hidden" name="employess_hidden_<? echo $my_role['id']; ?>" value="<? echo $my_employess['id']; ?>" />
<em><p class="role_checkbox"><input type="checkbox" name="role_checkbox[][<? echo $my_role['id']; ?>]" <? //if (mysql_num_rows($role_query) == 1) echo 'checked="checked"'; ?> value="<? echo $my_role['id']; ?>"/><? echo " " . $my_role['role']; ?> </p></em>
<? } ?>
<?
}
?>
<input value="Gem" name="add_contact_btn" type="submit" >
</form>
</div>
这是表架构: