What is wrong with this code, please help | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is wrong with this code, please help

error: Warning: mysqli_query() expects parameter 1 to be mysqli, string given in C:\xampp\htdocs\ap\a.php on line 28 Error: INSERT INTO feedback (Name, Email, Subject Matter ,Message) VALUES ('assda','sadsa','subject goes hsdaaasere','type in a dsad here') <?php $servername = "127.0.0.1"; $username = "root"; $password = "Password"; $dbname = "shop"; $name = $_POST['name']; $email= $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; // Create connection $conn = mysqli_connect($servername, $username, $password, $dbname); // Check connection if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } $sql="INSERT INTO feedback (Name, Email, Subject Matter ,Message) VALUES ('$name','$email','$subject','$message')"; if (mysqli_query($sql,$conn)) { echo "New record created successfully"; } else { echo "Error: " . $sql . "<br>" . mysqli_error($conn); } mysqli_close($conn); ?>

22nd Mar 2018, 11:09 AM
Mogammad Shameer Losper
Mogammad Shameer Losper - avatar
2 Answers
0
Thank you, the reason why my data wasnt being inserted into the database was because one of my column names in the table of my database had a space in it lol. What a frustratingly small mistake. I initially had the variables swapped the other way around but it still didnt work, i know why now lol. Thank you for your help.
22nd Mar 2018, 4:04 PM
Mogammad Shameer Losper
Mogammad Shameer Losper - avatar
+ 2
The connection is the first parameter and query is the second one
22nd Mar 2018, 3:06 PM
Toni Isotalo
Toni Isotalo - avatar