表格无线电不会插入数据库

时间:2022-09-25 20:11:05

I have a test with three radio options, and for each option being pressed I want that option to increase on 1 or whatever number I want and then add the count of each radio button being pressed to the database.

我有三个无线电选项的测试,并且对于每个选项被按下我希望该选项增加1或我想要的任何数字,然后将每个被按下的单选按钮的计数添加到数据库。

I have such table structure: two fields: color and clicks. Color has values: green, red, yellow.

我有这样的表结构:两个字段:颜色和点击。颜色有值:绿色,红色,黄色。

<?php

$a=mysql_connect('xxxx','xxxx','xxxx');

$b=mysql_select_db('xxxx',$a);


if ($_POST['submit']){


if ($_POST['color']=='green'){


$query='UPDATE tester SET clicks = clicks+1 WHERE color = "green"';

mysql_query($query);


 }

 if ($_POST['color']=='red'){


$query='UPDATE tester SET clicks = clicks+1 WHERE color = "red"';

mysql_query($query);

 }

 if ($_POST['color']=='yellow'){

$query='UPDATE tester SET clicks = clicks+1 WHERE color = "yellow"';

mysql_query($query);

 }

 }

?>

<form action="indexni.php" method="POST">
<input type="radio" name="color" value="green" />Green<br>
<input type="radio" name="color" value="red" />Red<br>
<input type="radio" name="color" value="yellow" />Yellow<br>
<input type ="submit" />
</form>

1 个解决方案

#1


0  

The value which you want to set i.e. clicks = clicks+1 in that what is the value of clicks?

您要设置的值,即点击次数=点击次数+1,即点击次数的值是多少?

If the value of clicks is the previous value of clicks of your table then first you have to write query of select on that table to get value of clicks.

如果点击的值是您的表的点击次数的先前值,那么首先您必须在该表上写入select的查询以获得点击的值。

#1


0  

The value which you want to set i.e. clicks = clicks+1 in that what is the value of clicks?

您要设置的值,即点击次数=点击次数+1,即点击次数的值是多少?

If the value of clicks is the previous value of clicks of your table then first you have to write query of select on that table to get value of clicks.

如果点击的值是您的表的点击次数的先前值,那么首先您必须在该表上写入select的查询以获得点击的值。