输入被复制 [英] The input are being duplicated
问题描述
在mysql行中更新时,我在重复数据时遇到问题.
我正在更改用户的床位,在表1上可以找到字段fname,这是用户名.然后发送到table2,然后已经使用rfname='$fname'
获得了fname,这是我的html弹出窗口,它由$ roommedical获取房间列表.希望不重复输入.或者我如何先删除过去的行值,然后再将其更新到另一行.,roommedical上的值是默认值,我唯一要更改的是rfname.
I'm having problem on duplication of data when updating in row of mysql.
I am changing bed of a user where I can get at table1 the field fname, which is the names of user. Then send to table2, then already get the fname using rfname='$fname'
, This is my html getting a pop up that get the list of room by $roommedical. Iwant To not duplicate the entry. or how can i delete first the past row value before updating it to other row., The value on roommedical is default the only i want to change is rfname.
<label class="selectDrop" >Check This For Room:</label>
<input class="selectDrop" type="checkbox" name="statmed" value="active" id="statmed" />
<label class="selectDrop11" >Medical Ward:</label>
<input class="selectDrop11" type=text id=medbed name=roommedical value="<?php echo $roommedical?>" placeholder="Select Medical Bed">
<!--BUTTON--><input class="selectDrop11" type="button" name="choice" onClick="selectValue('medbed')" value="Check">
这是我的提交表格php
And This is my submit form php
$roommedical = clean($_POST['roommedical']);
$statmed = clean($_POST['statmed']);
mysql_query("UPDATE room SET rfname='$fname',statmed='$statmed' Where roommedical='$roommedical'");
在更新患者姓名时,红色框线就是复制我的条目的示例.这是图片
When updating the patient name is duplicating the the red box line is the example of duplicating of my entry This is the picture
谢谢.我知道这很不好.请理解我.
Thank you. I am bad at this, I know. Please understand me.
推荐答案
如果患者要转移到另一张床,则需要在更新新床之前清除旧床.也是这样:
If the patient is moving to a different bed, you need to clear out the old bed before updating the new one. So do:
mysql_query("UPDATE room SET rfname='',statmed='None' Where rfname='$fname'");
mysql_query("UPDATE room SET rfname='$fname',statmed='$statmed' Where roommedical='$roommedical'");
顺便说一句,通常最好将第一个表中的id
用作第二个表中的外键,而不是名称.
BTW, in general it's preferable to use the id
from the first table as the foreign key in the second table, not the name.
这篇关于输入被复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!