Hi all, I'm trying to insert a row into a table via PHP. I have read multiple threads where other people have a similar issue but I can't seem to find the solution to mine. Hoping a fresh look will help.
A few things to note:
A multiquery with an INSERT INTO in the same table works.
This query exists in the middle of the code (not at the beginning like the multiquery). When I move the query to the beginning, still does not work.
I have tried date formats, number formats, with and without single quotes.
Inserting into a different table kind of works (the row gets inserted, category but the date and amount are not.
The code works in myPHPAdmin
I am using MAMP on a Mac
There are no PHP errors or Apache errors.
The MySQL errors are as follows:
2017-12-02 10:57:50 700000b4f000 InnoDB: Error: Table "mysql"."innodb_table_stats" not found.
2017-12-02 10:57:50 700000b4f000 InnoDB: Error: Fetch of persistent statistics requested for table "ginkgo"."exptrans" but the required system tables mysql.innodb_table_stats and mysql.innodb_index_stats are not present or have unexpected structure. Using transient stats instead.
2017-12-02 10:57:50 700000b4f000 InnoDB: Error: Table "mysql"."innodb_table_stats" not found.
2017-12-02 10:57:51 700000b4f000 InnoDB: Error: Table "mysql"."innodb_table_stats" not found.
2017-12-02 10:57:51 700000b4f000 InnoDB: Error: Fetch of persistent statistics requested for table "ginkgo"."fintrans" but the required system tables mysql.innodb_table_stats and mysql.innodb_index_stats are not present or have unexpected structure. Using transient stats instead.
2017-12-02 10:57:51 700000b4f000 InnoDB: Error: Table "mysql"."innodb_table_stats" not found.
2017-12-02 10:58:01 700000934000 InnoDB: Error: Table "mysql"."innodb_table_stats" not found.
2017-12-02 10:58:01 700000934000 InnoDB: Recalculation of persistent statistics requested for table "ginkgo"."fintrans" but the required persistent statistics storage is not present or is corrupted. Using transient stats instead.
2017-12-02 10:58:11 700000934000 InnoDB: Error: Table "mysql"."innodb_table_stats" not found.
2017-12-02 10:58:11 700000934000 InnoDB: Recalculation of persistent statistics requested for table "ginkgo"."exptrans" but the required persistent statistics storage is not present or is corrupted. Using transient stats instead.
Here is my code:
$mysqli = new mysqli('localhost:8889','root','root','Ginkgo');
if($mysqli->connect_errno){
echo ('Error connecting to MySQL server. '.$mysqli->connect_errno .' '.$mysqli->connect_error);
}
$sql = "INSERT INTO `FinTrans` (`Category`,`Location`,`FAmt`,`FDT`) values ('Tenant','514 Creekview',".$gross_rent[0].",'2000-01-01');";
echo $sql;
if( mysqli_query($mysqli,$sql))
{
echo 'success';
}else{
echo 'failed';
}
This is what is printed:
INSERT INTO FinTrans
(Category
,Location
,FAmt
,FDT
) values ('Tenant','514 Creekview',3200,'2000-01-01');success
This is the structure of the table:
CREATE TABLE `FinTrans` (
`Acct` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
`Clients` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
`Category` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
`Counterparty` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
`RentDate` date DEFAULT NULL,
`Description` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
`Location` varchar(255) CHARACTER SET latin1 DEFAULT NULL,
`Date Spent by Employee` date DEFAULT NULL,
`Date Reimbursed by Client` date DEFAULT NULL,
`ID` int(10) unsigned DEFAULT NULL,
`FDT` date DEFAULT NULL,
`FAmt` decimal(18,2) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
Thank you much for your help.
Sharlene