I am trying to insert data into mysqli
database. Connection to database established successfully. But data is not inserted.Even mysqli_eror()
not showing any error.
My code:
<?php
$name=$_POST['name'];
$email=$_POST['email'];
$password=$_POST['password'];
$con=mysqli_connect("localhost","root","password","vote") ||
die("couldn't connect to database");
if(!$con){
die("Could't connect to database. try again");
}
else{
echo "connected to db"; /* connection established successfully */
$query="INSERT INTO candidate(ID,name,email,password)
VALUES(0,'$name','$email','$password' ) ";
$result=mysqli_query($con,$query);
echo ($result)? '1':mysqli_error($con);
}
?>
Going to phpmyadmin
I run the same insert query and data was inserted.
But this code is not inserting data. Even mysqli_error($con) returning a empty string .
I am using XAMPP
on Ubuntu 14.04
[Please ask if any more information you need]
I think this is creating the problem,
$con=mysqli_connect("localhost","root","password","vote") ||
die("couldn't connect to database");
Change it to
$con=mysqli_connect("localhost","root","password","vote") or
^
die("couldn't connect to database");
Or
$con = mysqli_connect("localhost", "root", "password", "vote");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
If you are not seeing error, try adding, error_reporting(E_ALL);
in the file.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.