如何使用PHP一次在两个不同的表中插入数据?

时间:2017-05-14 12:49:49

标签: php sql mysqli

我想通过提交按钮

在两个表的相同数据库中插入相同的值
<table>
<form action="" method="post">
<tr>
<td> <input type="text" name="name" id="name" /> </td>
<td> <input type="submit" name="submit" id="submit" value="submit" /> </td>
</tr>
</form>
</table>   



$conn = mysqli_connect('localhost','root','','dbname');

if(isset($_POST["submit"]))
{

    $name= $name1 = $_POST["name"];
    $query1= "insert into course (name) values ('$name')";
    $result1 = mysqli_query($conn,$query1);

if (mysqli_num_rows($result1))
{
    echo "run";
}else{
    echo "not";
}


$query2= "insert into user (name) values ('$name1')";
$result2 = mysqli_query($conn,$query2);

if (mysqli_num_rows($result2) )
    echo "run";
}else{
    echo "not";
}

}

我收到警告: -

  

警告:mysqli_query():无法在第33行的D:\ Xampp \ xampp \ htdocs \ join_query \ insert.php中获取mysqli

     

警告:mysqli_num_rows()期望参数1为mysqli_result,在第35行的D:\ Xampp \ xampp \ htdocs \ join_query \ insert.php中给出null

     

     

警告:mysqli_query():无法在第46行的D:\ Xampp \ xampp \ htdocs \ join_query \ insert.php中获取mysqli

     

警告:mysqli_num_rows()要求参数1为mysqli_result,在第48行的D:\ Xampp \ xampp \ htdocs \ join_query \ insert.php中给出null

     

0 个答案:

没有答案