Sunday, January 27, 2019

php - My insert code does not work

I am new at web developing and I am still practicing. I have searched all possible answers to help me with my problem, but I still cannot insert my data to the database. I am using XAMPP version 3.2.2 and Sublime editor.




Here is my HTML form:




First name:
Last name:





and here is the PHP (inserting.php)




$user = 'root';
$pass = '';
$db = 'sample';

$con = mysqli_connect('localhost', $user, $pass, $db);


if($con){
echo 'success!';
}else echo 'not successful';

$sql = "insert into nameinfo (fname, lname) values ($_POST[fname],
$_POST[lname])";
$query = mysqli_query($con,$sql);

if ($query) {
echo 'good';

}else echo 'not good';

?>


When I run it, the connection succeeds, but it's not able to insert. Please help, thank you.

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...