我无法将$_GET方法保存到数据库,但它没有错误。它在数据库中有一个空记录。
<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";
}另外,我尝试回显$customizeColor1,2,3,它可以显示数据。堆栈溢出,我不知道为什么不能将数据保存在数据库中。
$_GET["p"],$_GET["c1"],$_GET["c2"],$_GET["c3"]就在这条路上,就像这样:customizeText.php?p=399&c1=Blue&c2=Red&c3=Green有人能帮我吗?
发布于 2016-03-28 14:19:35
天哪,我做到了,解决办法是这样的
<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";
}
} https://stackoverflow.com/questions/36264172
复制相似问题