gpt4 book ai didi

PHP - 在 MySQL 中输入不带引号的查询

转载 作者:行者123 更新时间:2023-11-29 21:00:38 24 4
gpt4 key购买 nike

我在尝试在 MySQL 中输入不带引号的数据时遇到问题。

下面是它在 MySQL 中的显示截图

DB ENTRY

下面是将其放入数据库的 INSERT INTO 代码,我需要将它输入到 MySQL 中而不带引号,这证明是具有挑战性的......

    <?php include('db_connect.inc');?>

<?php
$result = $conn->prepare("INSERT INTO dog_park.reviews (review_text, username, date, rating, item) VALUES (:review, :id, :date, :rating, :keyword)");
$result->bindParam(':review', $value1);
$result->bindParam(':id', $value2);
$result->bindParam(':date', $value3);
$result->bindParam(':rating', $value4);
$result->bindParam(':keyword', $value5);


$value1 = $_POST['review'];
$value2 = $_SESSION['id'];
$value3 = $date = date("Y-m-d");
$value4 = $_POST['rating'];
$value5 = $_SESSION['KEYWORD'];
$result->execute();
echo "Review entry Successful, you will now be redirected to the home page";

header( "refresh:10; url=index.php" );
?>

也许与 $_SESSION 有关?

最佳答案

也许修剪掉每个发布值两侧的无关引号可以为您解决问题,如下所示:

    <?php
include('db_connect.inc');
$result = $conn->prepare("INSERT INTO dog_park.reviews (review_text, username, date, rating, item) VALUES (:review, :id, :date, :rating, :keyword)");

$date = date("Y-m-d");
$value1 = trim($_POST['review'], "'\"");
$value2 = trim($_SESSION['id'], "'\"");
$value3 = trim($date, "'\"");
$value4 = trim($_POST['rating'], "'\"");
$value5 = trim($_SESSION['KEYWORD'], "'\"");

$result->bindParam(':review', $value1);
$result->bindParam(':id', $value2);
$result->bindParam(':date', $value3);
$result->bindParam(':rating', $value4);
$result->bindParam(':keyword', $value5);

$result->execute();
echo "Review entry Successful, you will now be redirected to the home page";

header( "refresh:10; url=index.php" );
?>

关于PHP - 在 MySQL 中输入不带引号的查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37257105/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com