Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/61.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)_Php_Mysql_Database_Syntax Error - Fatal编程技术网

更新表的列值并同时显示(PHP)

更新表的列值并同时显示(PHP),php,mysql,database,syntax-error,Php,Mysql,Database,Syntax Error,首先,我正在使用的系统是一个虚拟人力资源系统。现在,我有了这个profile.php页面,申请人的表单就在这里。该表格由她/他的基本资料组成,要求他/她设置申请人具备的技能。当申请人按下提交按钮时,它将转到test.php,页面将根据申请人在profile.php中输入的技能显示申请人有资格获得的可能工作 现在,我犯了这个错误 You have an error in your SQL syntax; check the manual that corresponds to your MySQL

首先,我正在使用的系统是一个虚拟人力资源系统。现在,我有了这个profile.php页面,申请人的表单就在这里。该表格由她/他的基本资料组成,要求他/她设置申请人具备的技能。当申请人按下提交按钮时,它将转到test.php,页面将根据申请人在profile.php中输入的技能显示申请人有资格获得的可能工作

现在,我犯了这个错误

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 'Specialist WHERE fname=Jamie' at line 2
下面是test.php中的代码,我试图在这里更新并显示employee表中的job列值

        $last = mysql_query("SELECT * from employee ") or die(mysql_error());

        echo "<table border='0' cellpadding='15' text-align = 'center' >";
        echo "<tr>";

            echo "<th>Name</th>";
            echo "</tr>";
            while($row2 = mysql_fetch_array( $last )){  
                $nym = $row2['fname'];  
            }

        $result = mysql_query("SELECT * FROM employee as t1,jobs as t2
                where t1.skills = t2.skills ") or die(mysql_error());

        while($row = mysql_fetch_array( $result )){
                $jt = $row['jobtitle'];
                $hey = mysql_query("UPDATE employee
                            SET job=$jt
                            WHERE fname=$nym")
                            or die(mysql_error()); 

                echo '<th><b><font color="#663300">' . $row['job'] . '</font></b><br></th>';
        }
这是我的员工数据库的快照

要快速修复,请将while循环更改为以下内容:

 while($row = mysql_fetch_array( $result )){
                $jt = $row['jobtitle'];
                $hey = mysql_query("UPDATE employee
                            SET job='$jt'
                            WHERE fname='$nym'")
                            or die(mysql_error()); 

                echo '<th><b><font color="#663300">' . $row['job'] . '</font></b><br></th>';
        }
请注意调用mysql\u查询时$nym变量周围的撇号

我强烈建议您更改查询并使用


否则,您的代码容易受到n次攻击

您可以使用以下方法实现:只需将$nym变量设置在适当的括号中即可

   $hey = mysql_query("UPDATE employee
                        SET job=$jt
                        WHERE fname= '".$nym."')
                        or die(mysql_error()); 

像这样更改查询

 $hey = mysql_query("UPDATE employee
                            SET `job`='$jt'
                            WHERE `fname`='$nym'")
                            or die(mysql_error()); 

谢谢你的提示。我尝试用您的代码更改它,但仍然出现相同的错误。对不起,我忘了在同一查询中还引用$jt变量。请尝试使用编辑的while并在出现错误消息时发布该消息。此操作有效。谢谢:现在,我将解决另一个问题,它也显示了所有过去显示的工作。好吧,谢谢你!等等,你的代码有点问题。我尝试了一次又一次,但它不会显示申请人可能的工作,除非申请人会重新加载页面@我只是想让你的查询有效,可能是你的逻辑出了问题,也许我会解决的。谢谢