Hallo Ich bin ein Anfänger Programmierer versucht, Werte (Kommentare) in eine Tabelle einzufügen. Ich habe die Insert-Funktionen vorher abgeschlossen, aber dieses Mal werden die Werte nicht eingefügt. Ich vermute, einer der Werte eingefügt, now()
verursacht das Problem. Nach der Fehlereinfügung, var_dump(ini_get('error_log'));
produziert string(0) ""
, wenn im Browser angezeigt. newcomment.phpFehler beim Einfügen von Werten in PHP zu phpmyadmin Fehler: string (0) ""
<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
error_reporting(E_ERROR);
try{
$conn = new mysqli("localhost", "XXXXXXXX_XXX", "XXXXXXX", "XXXXXXX");
$vendorid = $_GET["vendorid"];
$userid = $_GET["userid"];
$comment = $_GET["comment"];
$query = "insert into vendorcomments (comment, commentdate, vendorid, userid)
values ('" . addslashes($comment) . "', now() ,'" . addslashes($vendorid) . "','". addslashes($userid)."')";
$result = $conn->query($query);
if (!$result){
// unsuccessful insert
//$json_out = "[" . json_encode(array("result"=>0)) . "]";
var_dump(ini_get('error_log'));
}
else {
$json_out = "[" . json_encode(array("result"=>1)) . "]";
}
echo $json_out;
$conn->close();
}
catch(Exception $e) {
$json_out = "[".json_encode(array("result"=>0))."]";
echo $json_out;
}
?>
ich auch den Spaltenwert für now()
bearbeitet haben DATE_TIME as shown here UND here zu sein.
Zusätzliche Hinweise:
1) Die Parameter gesendet wurden, um korrekte, Benutzer-ID, VendorID und Kommentar alle Werte über gesendet haben.
2) xmlhttp.status == 200
!
3) Mein vendordetails Schema:
-- phpMyAdmin SQL Dump
-- version 4.3.7
-- http://www.phpmyadmin.net
--
-- Host: XXXXXXXXXXXXX
-- Generation Time: Dec 07, 2016 at 08:33 PM
-- Server version: 5.7.15
-- PHP Version: 5.4.45-0+deb7u4
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
/*!40101 SET @[email protected]@CHARACTER_SET_CLIENT */;
/*!40101 SET @[email protected]@CHARACTER_SET_RESULTS */;
/*!40101 SET @[email protected]@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
--
-- Database: `XXXXXXXXX`
--
-- --------------------------------------------------------
--
-- Table structure for table `vendorcomments`
--
CREATE TABLE IF NOT EXISTS `vendorcomments` (
`comment` varchar(300) COLLATE utf8_unicode_ci NOT NULL,
`commentdate` datetime(3) NOT NULL,
`vendorid` varchar(20) COLLATE utf8_unicode_ci NOT NULL,
`userid` varchar(50) COLLATE utf8_unicode_ci NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
--
-- Dumping data for table `vendorcomments`
--
INSERT INTO `vendorcomments` (`comment`, `commentdate`, `vendorid`, `userid`) VALUES
('eBay is working and its amazing, to be able to gain cashback.', '0000-00-00 00:00:00.000', '2', 'jimmy');
--
-- Indexes for dumped tables
--
--
-- Indexes for table `vendorcomments`
--
ALTER TABLE `vendorcomments`
ADD UNIQUE KEY `vendorid` (`vendorid`), ADD UNIQUE KEY `userid` (`userid`);
/*!40101 SET [email protected]_CHARACTER_SET_CLIENT */;
/*!40101 SET [email protected]_CHARACTER_SET_RESULTS */;
/*!40101 SET [email protected]_COLLATION_CONNECTION */;
Ihren Code zu kopieren versuche, sind anfällig für [SQL- Injektionen] (https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php). Bitte beginnen Sie mit vorbereiteten, parametrisierten Abfragen. –