J. Doe J. Doe - 4 months ago 15
SQL Question

Radiobox checked set value in db

In database this row is set as tinyint and it have default value as 1 and on my form I have 2 radiobox options.. how can I make if I check "Yes" value in db to be added as 2 and when I check "No" value in db to be added as 1

HTML CODE:

PHP code:

ohh and that row in database is called "exclusive"
And the form where are included those 2 radiobox when I press submit button it's imported in db.

Answer

First add the values you want to your 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>

Then add it to your query

$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']))
Comments