简体   繁体   English

单选按钮选择值

[英]Radio button selected value

I have a radio button on my page which is not a required field. 我的页面上有一个单选按钮,不是必填字段。 I was able to insert the data into MySQL if I select one of the Radio buttons. 如果选择单选按钮之一,则可以将数据插入MySQL。 If I don't select it and submit the page, I am getting "Internal server error occurred". 如果我没有选择它并提交页面,那么我将收到“发生内部服务器错误”。 I couldn't get the error message because the page is running on the production. 由于页面正在生产中运行,因此我无法收到错误消息。 It works fine on my development machine. 在我的开发机器上工作正常。 Here is my code. 这是我的代码。 Could you please let me know what could be the problem? 您能否让我知道可能是什么问题? Thank you. 谢谢。

<input type="radio" name="testRadio" value="radio1 value"> Radio 1 
<input type="radio" name="testRadio" value="radio2 value"> Radio 2

Here is my PHP code to get the POST value 这是我的PHP代码,用于获取POST值

$radioVal = $_POST["testRadio"];


"INSERT INTO TABLE1(radio_coulmn) VALUES ('" .$radioVal. "')";
if(!isset($_POST["testRadio"])){
   $radioVal = "";
}else{
   $radioVal = $_POST["testRadio"];
}

When you are submitting without selecting an option $_POST["testRadio"] doesn't exist, and $radioVal doesn't have a valid value. 提交时未选择任何选项时, $_POST["testRadio"]不存在,并且$radioVal没有有效值。 Put it like this - 这样说-

$radioVal = isset($_POST["testRadio"]) : $_POST["testRadio"] ? '';
"INSERT INTO TABLE1(radio_coulmn) VALUES ('$radioVal')";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM