Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/90.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用PHP将数组插入SQL表的单个字段_Php_Html_Mysql - Fatal编程技术网

如何使用PHP将数组插入SQL表的单个字段

如何使用PHP将数组插入SQL表的单个字段,php,html,mysql,Php,Html,Mysql,我有一些复选框条目,通过它们的html名称添加到列表中,如下所示: Choose no more than three categories:<br> <input id='category1' type="checkbox" name="boxsize[]" onclick="CountChecks('listone',3,this)" value="asian">Asian <input id='category2' type=

我有一些复选框条目,通过它们的html名称添加到列表中,如下所示:

    Choose no more than three categories:<br>
    <input id='category1' type="checkbox" name="boxsize[]" 
    onclick="CountChecks('listone',3,this)" value="asian">Asian
    <input id='category2' type="checkbox" name="boxsize[]" 
    onclick="CountChecks('listone',3,this)" value="asianFusion">Asian Fusion
当我回显$sanentry时,我将获得以下格式的选定值列表:asian,asian fusion。但是,当我尝试将这些值发送到mysql中的种族表时,种族列为空。下面是我用来将这些值发送到表中的post方法和查询

    $sanethnicity=mysqli_real_escape_string($con, $_POST['$sanentry']);
    $sql3="INSERT INTO 
    ethnicity(restaurant_id,ethnicity)VALUES('$sanrestid','$sanethnicity')";
    if ($con->query($sql3) === TRUE) {
    echo "New record in ethnicity table created \n";
    } else {
    die("Error: " . $sql3 . "<br>" . $con->error);
    }
    mysqli_close($con);
    ?>
$sanocidentity=mysqli\u real\u escape\u字符串($con,$\u POST['$sanentry']);
$sql3=“插入到
种族(餐厅id,种族)价值观(“$sanrestid”,“$sanrestid”)”;
if($con->query($sql3)==TRUE){
echo“已创建种族表中的新记录\n”;
}否则{
die(“错误:“.sql3.”
“$con->Error); } mysqli_close($con); ?>
“我的餐厅id”列没有问题,因为它正在更新,但对于插入的每一行,“种族”列始终为空。有人知道我做错了什么吗?
猜变量名是错误的。应该是
$sanethnicitydb
您的查询中有
$ethnicitydb

$sql3="INSERT INTO ethnicity(restaurant_id,ethnicity) VALUES('$sanrestid','$sanethnicity')";
另外,这是否是具有原始道德数组的字段<代码>$\u POST['$sanentry']或已内爆。你可能想要这个:

$sanethnicity=mysqli_real_escape_string($con, $sanethnicity);
由于
$SAN
之前是从seomthing中内爆的,例如:

$sanethnicity = implode(',',$_REQUEST["boxsize"]);

在这一行中,您试图使用$sanentry作为$\u POST中的条目

$sanethnicity=mysqli_real_escape_string($con, $_POST['$sanentry']);
应该是

$sanethnicity=mysqli_real_escape_string($con, $sanentry);

虽然-您应该考虑使用准备好的语句和绑定变量。

如果您想在不丢失数组结构的情况下存储它,那么您应该使用打字?将
$\u POST['sanentry']
更改为
$\u POST['sanentry']
您只是在尝试从技术上插入字符串。也许字符串太长了,是为了列还是别的什么。您没有收到任何sql错误吗?sql探查器说什么?我没有收到sql错误。种族列每次都显示为空白。此外,我对种族列varchar(255)进行了限制,因此该列应该太长
$sanethnicity=mysqli_real_escape_string($con, $sanentry);