Radiobox检查db中的设定值

时间:2016-07-29 15:48:37

标签: php html mysql

在数据库中,此行设置为tinyint,默认值为1,在我的表单上我有2个radiobox选项..如果我检查"是"将db中的值添加为2,当我检查"否" db中的值将被添加为1

HTML CODE:

<label class="radio-inline">
<input type="radio" name="inlineRadioOptions" id="inlineRadio1" value="option1"> Yes
 </label>
<label class="radio-inline">
<input type="radio" name="inlineRadioOptions" id="inlineRadio2" value="option2" checked="checked"> No
 </label>

PHP代码:

    $pdo = new PDO('mysql:host=;dbname=', '', '');

$statement = $pdo->prepare("INSERT INTO games (name, url, yt_id, steam_id, source) VALUES (?, ?, ?, ?, ?, ?)");
$statement->execute(array($_POST['gtitle'], $_POST['keysl'], $_POST['video_id'], $_POST['appid'], $_POST['slink']));
哦,数据库中的那行被称为&#34; exclusive&#34; 当我按下它在db中导入的提交按钮时,包含那些2个radiobox的表格。

1 个答案:

答案 0 :(得分:0)

首先将您想要的值添加到HTML

<label class="radio-inline">
<input type="radio" name="inlineRadioOptions" id="inlineRadio1" value="2"> Yes
 </label>
<label class="radio-inline">
<input type="radio" name="inlineRadioOptions" id="inlineRadio2" value="1" checked="checked"> No
 </label>

然后将其添加到您的查询

$statement = $pdo->prepare("INSERT INTO games (name, url, yt_id, steam_id, source, exclusive) VALUES (?, ?, ?, ?, ?, ?)");
$statement->execute(array($_POST['gtitle'], $_POST['keysl'], $_POST['video_id'], $_POST['appid'], $_POST['slink']),$_POST['inlineRadioOptions']))