使用php向mysql表中添加多个值

使用php向mysql表中添加多个值,php,html,mysql,database,Php,Html,Mysql,Database,我有这个密码 <form action="MyCurrentPage.php" method="post" > <label for="name_of_trainer"> Name Trainer </label> <input type="text" name="name_of_trainer" id="name_of_trainer"/> <label for="double"> yearly Inc

我有这个密码

    <form action="MyCurrentPage.php" method="post" >
    <label for="name_of_trainer"> Name Trainer </label>
    <input type="text" name="name_of_trainer" id="name_of_trainer"/>
    <label for="double"> yearly Income </label>
    <input type="text" name="yearly_income id="yearlyincome"/>
<input type= "submit" value="submit" name="submit" />
</form>

?php
 if (isset($_POST['submit'])) {
     $yearly_income_adition=$_POST['name_of_trainer'];
     $yearly_income=$_POST['yearly_income'];
     $mysqli->select_db("trainers");

    $sql="INSERT INTO trainers (titleCD, yearly_income) VALUES ('".$yearly_income_adition."','".$yearly_income.'")";
    $mysqli->query($sql);

     }

?>   

姓名培训师
年收入
查询($sql);
}
?>   
我用它向我的数据库中插入新值,但它不起作用,没有添加值,我没有得到任何错误。是否有语法错误?

请尝试:

$sql="INSERT INTO trainers (titleCD, yearly_income) VALUES ('".$yearly_income_adition."','".$yearly_income."')";
请注意最后一个


此外,正如@Webeng所评论的,了解。养成这种习惯非常重要。

你缺少两件事:

?php
应该是
为什么要检查这个

if (isset($_POST['submit'])) {
将其更改为:

if (isset($_POST['yearly_income'])) {

这表明代码在同一页或不同页上?您可以选择查询吗?请检查您的代码是否容易受到sql注入的攻击,这意味着如果黑客设法路过并使用您的代码,他们可以执行诸如删除数据库中的所有表之类的操作,或者更糟的是,获取信息并找到从中获利的方法。在年收入$U之后……我很确定应该是这样的“那么‘那么:’年收入’”);你不会得到任何错误,因为你没有检查它们。除非明确启用异常。mysqli返回布尔值false失败。在我的评论之前2秒,很好!;)