Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/265.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/security/4.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 如果值为null,如何在数据库中插入字符串_Php_Mysqli - Fatal编程技术网

Php 如果值为null,如何在数据库中插入字符串

Php 如果值为null,如何在数据库中插入字符串,php,mysqli,Php,Mysqli,在绑定参数中,我尝试为每个问题插入答案。我有一个简单的问题,就是如果一个问题没有答案,我如何在db中插入单词no-answer?这是因为此时它不会在答案为空的位置插入任何行。仅当问题至少有一个答案时才插入 以下是尝试: $results = $_POST['value']; foreach($results as $id => $value) { $answer = $value; $quesid = $question_ids[$id]; if($an

在绑定参数中,我尝试为每个问题插入答案。我有一个简单的问题,就是如果一个问题没有答案,我如何在db中插入单词
no-answer
?这是因为此时它不会在答案为空的位置插入任何行。仅当问题至少有一个答案时才插入

以下是尝试:

$results = $_POST['value'];
foreach($results as $id => $value) 
{
    $answer = $value;

    $quesid = $question_ids[$id];   

    if($answer = ''){
        $answer = 'No Answer';
    }

    foreach($value as $answer) 
    {
        $insertanswer->bind_param("is", $quesid, $answer);

        $insertanswer->execute();

        if ($insertanswer->errno) {
            // Handle query error here
            echo __LINE__.': '.$insertanswer->error;
            break 7;
        }
    }
}

它看起来像是在if条件下使用赋值运算符(
=
),我认为它应该是比较运算符(
=

应该是

if($answer == ''){
        $answer = 'No Answer';
    }

另外,如果要确保
$question\u id[$id]
为int,则可以使用

$quesid  = (int)$question_ids[$id];

它看起来像是在if条件下使用赋值运算符(
=
),我认为它应该是比较运算符(
=

应该是

if($answer == ''){
        $answer = 'No Answer';
    }

另外,如果要确保
$question\u id[$id]
为int,则可以使用

$quesid  = (int)$question_ids[$id];

检查它是否为空是不够的,你应该检查null以防万一

//Take notice of === (Identical operator)
    if($answer == '' || $answer === null){
            $answer = 'No Answer';
        }

检查它是否为空是不够的,你应该检查null以防万一

//Take notice of === (Identical operator)
    if($answer == '' || $answer === null){
            $answer = 'No Answer';
        }

如果是文本输入,则
If($answer=''| |$answer====null){
,如果是从下拉菜单中输入,则检索值:
If($answer=''){/''是此选项的任何值
如果是文本输入,则
If($answer=''|$answer==null){
,如果从下拉菜单中输入,则检索值:
如果($answer=''){/''是此选项的任何值

当我有一个没有答案的问题时,它似乎仍然不会插入任何记录如果($empty{$answer])如果($empty{$answer answer),它应该是
如果($empty{$answer code>)
?尝试了此操作但不起作用或者它应该是
空($answer
trim($answer)=''再次原谅我错了,这只是一个输入错误我应该说
$\u POST['value']
来自这里:
var$newBtn=$(“”)替换('%s',$this.is(':visible')?'inline block':'none').attr('name',“value[“+gQuestionIndex+”)[]).attr('value',$this.val()).attr('class',$this.attr('class')).attr('id',$this.attr('id')+'Row');
。这是一个按钮尝试了空和修剪方法,但仍然没有运气。Kn var dump for
$result
当没有答案
空数组(1)
当我有一个没有答案的问题时,它似乎仍然没有插入任何记录它应该是
if($empty{$answer
?尝试了这个,但不起作用,或者它应该是
空($answer)
或者
trim($answer)=''
再次请原谅我错了,这只是一个输入错误。我应该说
$\u POST['value']
来自这里:
var$newBtn=$(“”)。替换('%s',$this.is('visible')?'inline block':'none')).attr('name','value[”+gQuestionIndex+“][]”.attr('value',$this.val()).attr('class',$this.attr('class')).attr('id',$this.attr('id')+'Row');
。这是一个按钮输入了空方法和修剪方法,但仍然没有运气。
$result
的Kn var dump在没有答案时显示此值。
空数组(1)