首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >无法在数据库2中保存$_REQUEST方法

无法在数据库2中保存$_REQUEST方法
EN

Stack Overflow用户
提问于 2016-03-28 14:15:33
回答 1查看 51关注 0票数 0

我无法将$_GET方法保存到数据库,但它没有错误。它在数据库中有一个空记录。

代码语言:javascript
复制
<form action="customizeText.php?" method="get" >
            <?php
                $customizeName =  '1set';
                $customizePrice = $_GET['p'];
                $customizeColor1 = $_GET['c1'];
                $customizeColor2 = $_GET['c2'];
                $customizeColor3 = $_GET['c3'];
                $customizeText1 = 'I';
                $customizeText2 = 'L';
                $customizeText3 = 'U';
                $customizePackage = 'red';
                $quantity = 1;
            ?>

            <div><strong><?php echo $customizeName; ?></strong></div>
            <div class="product-price"><?php echo "$".$customizePrice; ?></div>
            <?php echo $customizeColor1; ?>
            <?php echo $customizeColor2; ?>
            <?php echo $customizeColor3;?>
            <div>
            <input type="submit" value="Add to cart" class="btnAddAction" name="btnAddAction" /></div>

</form>

<?php     
if (isset($_GET['btnAddAction'])) { 

    $sql= "INSERT INTO customizeproduct (custProName, custProPrice, custProColor1, custProColor2, custProColor3, custProText1, custProText2, custProText3, custProPackage) VALUES ('$customizeName', '$customizePrice', '$customizeColor1', '$customizeColor2', '$customizeColor3', '$customizeText1', '$customizeText2', '$customizeText3', '$customizePackage')";
                if (mysqli_query($connect, $sql)){
                    echo "SAVE IN DB";
                        }else{
                            echo "NO WAY";  
                        }

另外,我尝试回显$customizeColor123,它可以显示数据。堆栈溢出,我不知道为什么不能将数据保存在数据库中。

  • $_GET["p"]$_GET["c1"]$_GET["c2"]$_GET["c3"]就在这条路上,就像这样:customizeText.php?p=399&c1=Blue&c2=Red&c3=Green

有人能帮我吗?

EN

回答 1

Stack Overflow用户

发布于 2016-03-28 14:19:35

天哪,我做到了,解决办法是这样的

代码语言:javascript
复制
<form action="customizeText.php?" method="post" >
<input type="hidden" name="p" value="<?php echo htmlspecialchars($_GET['p'], ENT_QUOTES); ?>" />
<input type="hidden" name="c1" value="<?php echo htmlspecialchars($_GET['c1'], ENT_QUOTES); ?>" />
<input type="hidden" name="c2" value="<?php echo htmlspecialchars($_GET['c2'], ENT_QUOTES); ?>" />
<input type="hidden" name="c3" value="<?php echo htmlspecialchars($_GET['c3'], ENT_QUOTES); ?>" />
            <?php
                $customizeName =  '1set';
                $customizePrice = $_POST['p'];
                $customizeColor1 = $_POST['c1'];
                $customizeColor2 = $_POST['c2'];
                $customizeColor3 = $_POST['c3'];
                $customizeText1 = 'I';
                $customizeText2 = 'L';
                $customizeText3 = 'U';
                $customizePackage = 'red';
                $quantity = 1;
            ?>
            <div><strong><?php echo $customizeName; ?></strong></div>
            <div class="product-price"><?php echo "$".$_GET['p']; ?></div>
            <?php echo $_GET['c1']; ?>
            <?php echo $_GET['c2']; ?>
            <?php echo $_GET['c3'];?>
            <div>
            <input type="submit" value="Add to cart" class="btnAddAction" name="btnAddAction" /></div>

</form>

<?php     
if (isset($_POST['btnAddAction'])) { 

    $sql= "INSERT INTO customizeproduct (custProName, custProPrice, custProColor1, custProColor2, custProColor3, custProText1, custProText2, custProText3, custProPackage) VALUES ('$customizeName', '$customizePrice', '$customizeColor1', '$customizeColor2', '$customizeColor3', '$customizeText1', '$customizeText2', '$customizeText3', '$customizePackage')";
    if (mysqli_query($connect, $sql)){
        echo "SAVE IN DB";
    }else{
        echo "NO WAY";
    }   
}       
票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36264172

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档