The code is as follows, why the form data cannot be inserted into the database table. What's going on? !
<?php
$conn = mysqli_connect('localhost','root','','thdb');
$sql = "insert into info2 (name,tel,demo) values('$_POST[name]','$_POST[tel]','$_POST[demo]')" ;//Prepare sql
mysqli_query( $conn,$sql);
?>
To troubleshoot the problem, you can start with the database. Write a SQL statement to insert a piece of data. If it works, check your PHP code again.
Try it
There is a problem with this statement. The difference between single quotation marks and double quotation marks is not clear. Single quotes do not interpret variables. Change to double quotes "$_POST[tel]"
Another problem: After connecting to the database, the data table is not selected. Take a look and see what you are missing
I won’t tell you directly what’s wrong.
First: You need to find errors yourself. Have you installed the navicat software? Print out the sql statement, copy it and run it, and check the running results. Other sql management software is also available.
Second: I don’t know if it’s a problem you copied, or if it’s always like this. Space Space Space Pay attention to the spaces.
Third: The first thing after connecting to the database is to print the database $con to determine whether it is connected.