我真的不知道为什么,但是我有一个查询,该查询在被PHP处理时将无法正常工作,并且如果在PHP完整查询的回显之后进行复制和粘贴,则该查询会很好地工作。
这是我的查询:
$name = $_POST["name"];
$surname = $_POST["surname"];
$street_name = $_POST["address"];
$street_no = $_POST["houseno"];
$tel = $_POST["telephone"];
$email = $_POST["email"];
$product = "turbomaxblue";
if(isset($_POST["comment"])) $comment = $_POST["comment"]; else $comment = "";
$city = $_POST["city"];
$town = $_POST["region"];
$price = $_POST["price"];
$quantity = $_POST["quantity"];
$state = $_POST["state"];
$townid = $_POST["townid"];
$data = date('Y-m-d H:i:s');
$status = "PENDING";
$page = "prova";
$query = "INSERT INTO ordini (name,
surname,
street_name,
street_no,
tel,
email,
product,
comment,
city,
town,
price,
quantity,
state,
townid,
status,
page)
VALUES ('".$name."',
'".$surname."',
'".$street_name."',
'".$street_no."',
'".$tel."',
'".$email."',
'".$product."',
'".$comment."',
'".$city."',
'".$town."',
'".$price."',
'".$quantity."',
'".$state."',
'".$townid."',
'".$status."',
'".$page."')";
$stmt = $dbh->query($query);
/*COMMENTED
$stmt->bindParam(":name",$name,PDO::PARAM_STR);
$stmt->bindParam(":surname",$surname,PDO::PARAM_STR);
$stmt->bindParam(":street_name",$street_name,PDO::PARAM_STR);
$stmt->bindParam(":street_no",$street_no,PDO::PARAM_STR);
$stmt->bindParam(":tel",$tel,PDO::PARAM_STR);
$stmt->bindParam(":email",$email,PDO::PARAM_STR);
$stmt->bindParam(":product",$product,PDO::PARAM_STR);
$stmt->bindParam(":comment",$comment,PDO::PARAM_STR);
$stmt->bindParam(":city",$city,PDO::PARAM_STR);
$stmt->bindParam(":town",$town,PDO::PARAM_STR);
$stmt->bindParam(":price",$price,PDO::PARAM_STR);
$stmt->bindParam(":quantity",$quantity,PDO::PARAM_INT);
$stmt->bindParam(":state",$state,PDO::PARAM_STR);
$stmt->bindParam(":townid",$townid,PDO::PARAM_INT);
$stmt->bindParam(":status",$status,PDO::PARAM_STR);
$stmt->bindParam(":page",$page,PDO::PARAM_STR);
*/
echo $query; // this is the one I copy in phpmyadmin
?>
所有变量都有一个值,实际上我在phpMyAdmin中复制代码时会使用这些变量中的数据。这是我的MySQL表:
当o显示要在phpMyAdmin中测试的查询时,这是输出示例:
INSERT INTO ordini (name, surname, street_name, street_no, tel, email, product, comment, city, town, price, quantity, state, townid, status, page) VALUES ('sdf', 'sdf', 'efdf', 'sdfsdf', '333', 'sdf', 'turbomaxblue', '', 'AKWA IBOM, UYO, Akpan St.', 'UYO, Akpan St.', '14500', '1', 'NG', '5064', 'PENDING', 'prova')