如何在单列,不同行的mysql数据库中存储3单选按钮列表? [英] How do store 3 radio button lists in mysql database in single column, different rows?
本文介绍了如何在单列,不同行的mysql数据库中存储3单选按钮列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的ratings.php(html代码)
This is my ratings.php (html codes)
<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">
因此,当用户选择该值时,将生成以下代码插入数据库: p>
So when users select the value, it will generate the below codes here to insert into database:
<?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数据库
- >
I want to store like this in mysql database ->
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中?请帮助谢谢!
How do I make the values store into mysql? Please help thanks!
推荐答案
您的 $ rating
是一个数组
您应该存储 $ rating [0]
或 $ rating [1]
或 $ rating [2]
,所以要存储它们,你可以管理他们在php wich按钮被选择或点击然后存储在你的表
you should stor values like that $rating[0]
or $rating[1]
or $rating[2]
, so to store them like that u can manage them in php wich button is selected or clicked then store them in your table
这篇关于如何在单列,不同行的mysql数据库中存储3单选按钮列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文