沃梦达 / 编程问答 / php问题 / 正文

使用 PHP 将单选按钮值添加到 MYSQL 表

Adding radio button values to MYSQL table using PHP(使用 PHP 将单选按钮值添加到 MYSQL 表)

本文介绍了使用 PHP 将单选按钮值添加到 MYSQL 表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PHP/MYSQL 创建一个包含单选按钮的表单.我正在尝试将选中的单选按钮的值添加到数据库中的表中.目前我无法将任何内容添加到数据库中.该表称为评估.

I am using PHP/MYSQL to create a form that includes radio buttons. I am trying and add the value of checked radio buttons to a table within a database. At the minute I can't get anything to add to the database. The table is called assessment.

QUESTION1.PHP

<?php 
include 'core/init.php';
include 'includes/overall/overall_header.php';
protect_page();
include 'includes/menu.php';
include 'includes/overall/navigate.php';
include 'includes/widgets/loggedin.php';

?>      

<h1>Assessment</h1>

<form action="save.php" method="post">

<p class="p1">
Question 1</p>
<p class="p4">
Are you tall or short?</p>

<p class="p3"> 
<input type="radio" name="q1" value="1" />
1
<input type="radio" name="q1" value="2" />
2
<input type="radio" name="q1" value="3" />
3
<input type="radio" name="q1" value="4" />
4
<input type="radio" name="q1" value="5" />
5
</p><br><br>
</form>

<img src="Images/image1.png" alt="Submit" class="thumbnail" align="right" width="58"      height="52" id="question2">
<img src="Images/save.png" alt="Submit" class="thumbnail" align="right" width="65" height="52">

<?php
}
 include 'includes/overall/overall_footer.php'; 
 ?>  

SAVE.PHP

<?php
session_start();
include('connection.php');
$q1=$_POST['q1'];
mysql_query("INSERT INTO `assessment` (q1) VALUES ('$q1')");
header("location: question2.php?");
mysql_close($con);
?>

推荐答案

我想知道,这两个图像TAG的目的是什么.我只是将那些 img 标签更改为按钮图像.

i would like to know, what is the purpose of these two image TAG. i just changed those img tag into button image .

<h1>Assessment</h1>
<form action="save.php" method="post">
  <p class="p1"> Question 1</p>
  <p class="p4"> Are you tall or short?</p>
  <p class="p3">
    <input type="radio" name="q1" value="1" />
    1
    <input type="radio" name="q1" value="2" />
    2
    <input type="radio" name="q1" value="3" />
    3
    <input type="radio" name="q1" value="4" />
    4
    <input type="radio" name="q1" value="5" />
    5 </p>
  <br>
  <br>
  <input type="image" src="Images/image1.png" />
  <input type="image" src="Images/save.png" />
</form>

save.php

 <?php
    if (isset($_POST['q1'])){
        $q1 = $_POST['q1'];
        mysql_query("INSERT INTO assessment (q1) VALUES ('$q1')");
    }
    ?>

这篇关于使用 PHP 将单选按钮值添加到 MYSQL 表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:使用 PHP 将单选按钮值添加到 MYSQL 表

基础教程推荐