First of all I hope you are having a great day. My question is about putting data from a form into different tables from a Database. I have been struggling for days with this error, I tried to find a solution on the web, but I wasn't able, so that is why I come to you all.
首先,我希望你有一个美好的一天。我的问题是将表单中的数据放入数据库的不同表中。我一直在努力解决这个错误,我试图在网上找到解决方案,但我无法做到,所以这就是为什么我来找你们。
These is the message that I receive:
这些是我收到的消息:
Warning: mysqli_query() expects parameter 1 to be mysqli, string given in /Applications/MAMP/htdocs/Royston_app /php/reportcreated.php on line 14 Warning: mysqli_query() expects parameter 1 to be mysqli, string given in /Applications/MAMP/htdocs/Royston_app /php/reportcreated.php on line 15
警告:mysqli_query()期望参数1为mysqli,第14行/ Applications / MAMP / htdocs / Royston_app /php/reportcreated.php中给出的字符串警告:mysqli_query()期望参数1为mysqli,在/ Applications /中给出字符串第15行的MAMP / htdocs / Royston_app /php/reportcreated.php
And here is my code:
这是我的代码:
I also would like if you could help me recommending me some books or powerful material about back end, so I am a new student who wants to learn and it is trying to code a web application with coordinates that I will need to insert into another table too.
我也想,如果你能帮我推荐一些关于后端的书籍或强大的资料,那么我是一个想要学习的新学生,它试图编写一个带有坐标的Web应用程序,我需要将其插入到另一个表中太。
Thank you very much!
非常感谢你!
<?php
if(isset($_POST['submit'])){
$conn=mysqli_connect("localhost","root","root");
if(!$conn)
{
die("Conection with db failed." . mysql_error());
}
$sql1 = "INSERT INTO users (user_id, name, last_name, email)
VALUES (NULL,'$_POST[name]','$_POST[last_name]','$_POST[email]')";
$sql2 = "INSERT INTO image (image_id,date_creation)
VALUES (NULL,'DD/MM/YYYY')";
mysqli_query($sql1, $conn);
mysqli_query($sql2, $conn);
mysqli_close($conn);
}
?>
2 个解决方案
#1
1
Use link then query per the mysqli_query manual:
根据mysqli_query手册使用链接然后查询:
mysqli_query($conn,$sql1);
#2
1
you are missing the db name
你缺少数据库名称
$db_link = mysqli_connect('localhost','root','root','users');
the fisrt root is your db username, the second one is the password for that user and users is the database name
fisrt root是您的db用户名,第二个是该用户的密码,users是数据库名称
#1
1
Use link then query per the mysqli_query manual:
根据mysqli_query手册使用链接然后查询:
mysqli_query($conn,$sql1);
#2
1
you are missing the db name
你缺少数据库名称
$db_link = mysqli_connect('localhost','root','root','users');
the fisrt root is your db username, the second one is the password for that user and users is the database name
fisrt root是您的db用户名,第二个是该用户的密码,users是数据库名称