I am having trouble inserting data in the mySQL through php,
First of all i created the Database and its table using PHpmyadmin,
my table is as follows,
CREATE TABLE users (
firstsname varchar(12) NOT NULL,
lastname varchar(20) NOT NULL,
gender varchar(6) NOT NULL,
dob varchar(10) NOT NULL,
address varchar(40) NOT NULL,
town varchar(20) NOT NULL,
states varchar(20) NOT NULL,
postcode int(4) NOT NULL,
emailaddress varchar(100) PRIMARY KEY UNIQUE,
phonenumber int(10) NOT NULL,
comments varchar(1000) NULL
);
After I created the table i connect to the database where this table is located called testing
, using this code,
$host = "localhost";
$user = "root";
$pwd = "";
$sql_db = "testing";
$conn = @mysqli_connect($host,$user,$pwd,$sql_db);
if (!$conn) {
echo "<p>Connection has failed!</p>";
} else {
echo "<p>Success</p>";
}
I get Success
message on the screen that means the connection is successful, but when I try to write in to this table using PHP i always get error, but when I run the same query in phpmyadmin then it works and add the table row into database,
This is what I am doing in PHP,
$query = "INSERT INTO users ('firstname', 'lastname', 'gender', 'dob', 'address', 'town', 'states', 'postcode', 'emailaddress', 'phonenumber', 'comments')
VALUES ('asds', 'adssad', 'male', '04/08/1991', 'saddadsasd', 'dasasd', 'adssad', '1111', 'dasdas@dassda.com', '1111111111', 'adssaddsadsa')";
$result = mysqli_query($conn, $query);
if (!$result){
echo "ERROR";
} else {
echo "Done";
}
mysqli_close ($conn);
and I always get ERROR when I run it.
Why it works through phpmyadmin but not with PHP ?