这是我的 rating.php(html 代码)
<input type="radio" name="selectThree" value="1">
<input type="radio" name="selectThree" value="2">
<input type="radio" name="selectThree" value="3">
<input type="radio" name="selectThree" value="4">
<input type="radio" name="selectThree" value="5">
<input type="radio" name="selectTwo" value="1">
<input type="radio" name="selectTwo" value="2">
<input type="radio" name="selectTwo" value="3">
<input type="radio" name="selectTwo" value="4">
<input type="radio" name="selectTwo" value="5">
<input type="radio" name="selectOne" value="1">
<input type="radio" name="selectOne" value="2">
<input type="radio" name="selectOne" value="3">
<input type="radio" name="selectOne" value="4">
<input type="radio" name="selectOne" value="5">
因此,当用户选择该值时,它将在此处生成以下代码以插入数据库:
<?php
include_once "mysqli.connect.php";
include_once "config.php";
if(isset($_POST['Click']))
{
$rating = explode($_POST['selectOne'], $_POST['selectTwo'], $_POST['selectThree']);
$_SESSION['commentInput'] = array();
$_SESSION['commentInput'][] = $_POST['comment'][0];
$_SESSION['commentInput'][] = $_POST['comment'][1];
$_SESSION['commentInput'][] = $_POST['comment'][2];
if(isset($_REQUEST["comment"]))
{
$merge = array_combine ($_SESSION['product'],$_SESSION['commentInput']);
foreach($merge as $key => $value)
{
$sqlComment = "INSERT into comment (comment, product) VALUES ('".$value."', '".$key."')";
$result = $mysqli->query($sqlComment);
}
echo"<script type='text/javascript'>alert('Thank you for your comment!' )</script>";
}
else
{
echo "<script type='text/javascript'>alert('Please comment!')</script>";
}
}
我想这样存储在mysql数据库中->
product|rating
--------------
shirt | 2
pants | 3
dress | 5
但现在它像这样存储:
product|rating
--------------
shirt | Array
pants | Array
dress | Array
在我使用这个之后->
$rating = explode($_POST['selectOne'], $_POST['selectTwo'], $_POST['selectThree']);
//mysql
$sqlRating = "INSERT into ratings (product, rating) VALUES ('".$key."', '".$rating."')";
$result = $mysqli->query($sqlRating);
如何将值存储到 mysql 中?请帮忙谢谢!