Inserting data from a form into different tables from a Database

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

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.

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);
}
?>
javascriptphpdatabasemysqli

Answers

answered 1 week ago AbsoluteƵERØ #1

Use link then query per the mysqli_query manual:

mysqli_query($conn,$sql1);

answered 1 week ago GJCode #2

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

comments powered by Disqus