我想使用php更新数据库(mysql)中的单选按钮的值 [英] I want to update a value of radio button in database (mysql) using php
问题描述
我是php和mysql的新手。我已经使用单选按钮来保存我的帐户记录的类型我可以成功插入数据但当我尝试从sql获取该数据(无论是选择类型S还是选择类型T)来进一步更新它我无法做到这一点。我不知道如何从我的sql获取单选按钮的数据..请帮助
I am new to php and mysql. i've used radio buttons to save the type of my account records i can insert the data successfully but when i try to get that data (whether type S is selected or type T is selected) from sql to update it further i cant do that. i dont know how to get the data of radio buttons from my sql.. please help
<form method="post" action="users-edit-action.php">
<input type="hidden" value="<?php echo $accountid; ?>" name="id" />
<label>Email/Username:</label><input type="text" name="email" value="<?php echo $email; ?>" /><br /><br />
<label>Password:</label><input type="password" name="password" value="<?php echo $password;?>" /><br /><br />
<label>First Name:</label><input type="text" name="firstname" value="<?php echo $firstname; ?>" /><br /><br />
<label>Last Name:</label><input type="text" name="lastname" value="<?php echo $lastname; ?>" /><br /><br />
<label>Type:</label><br />
<input type="radio" name="type" value="<?php echo $type; ?>" /> Student<br />
<input type="radio" name="type" value="<?php echo $type; ?>" /> Teacher<br />
<input type="submit" value="Edit" />
</form>
这是我从数据库中获取价值的方式..我确定我做错了,请帮我解决这个..
this is how i get the value from database.. im sure iam doing wrong, please help me solve this..
推荐答案
您必须检查从数据库中获取的类型,并根据该类型将此属性添加到input元素: checked =checked
。所以整个选定的标签看起来像这样:
You have to check which type you got from the database and according to that add this attribute to the input element: checked="checked"
. So the whole selected tag would look like this:
< input name =typetype =radiochecked =checkedvalue =PHP返回的那个/>
另一个输入标记也在那里,但没有选中
属性。
您只需要对要放置属性的元素进行PHP检查。
And the other input tag would also be there, but without the checked
attribute.
You just need to do the PHP check on what element to put the attribute.
整个部分:
<input type="radio" name="type" value="S" <?php if ($type == 'S') echo 'checked="checked"'; ?>" /> Student<br />
<input type="radio" name="type" value="T" <?php if ($type == 'T') echo 'checked="checked"'; ?>" /> Teacher<br />
这篇关于我想使用php更新数据库(mysql)中的单选按钮的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!