简体   繁体   English

从HTML表单插入到&从数据库表插入

[英]INSERT INTO from HTML form & INSERT FROM database TABLE

-- UPDATED -- - 更新 -

I am trying to INSERT data from a HTML FORM and a database TABLE(1) INTO TABLE(2). 我正在尝试将HTML FORM和数据库TABLE(1)的数据插入TABLE(2)。 The below code works partially. 以下代码部分起作用。 So far data from table1 does insert into table2, as well as incrementing (having the same user enter multiple form data). 到目前为止,来自table1的数据确实会插入到table2中,并会递增(必须由同一用户输入多个表单数据)。 But the UPDATE data is not inserting. 但是未插入UPDATE数据。 When I check the table values, after submitting the form, room_temp shows the same 1 of 3 options (even if I've not selected it) and stage1 - stage10 shows the value of 0, even if I've entered 1,2,3 etc.... 当我检查表格值时,提交表单后,room_temp会显示3个选项中的相同选项(即使我尚未选择),stage1-stage10也会显示0值,即使我输入了1,2, 3等...

           $sql = "
            INSERT INTO table2 (user_id, user_fname, user_lname, user_dob)
            SELECT user_id, user_fname, user_lname, user_dob FROM table1;

            UPDATE table2 SET 

            room_temp='$rtemp',
            stage1='$ustage1',
            stage2='$ustage2',
            stage3='$ustage3',
            stage4='$ustage4',
            stage5='$ustage5',
            stage6='$ustage6',
            stage7='$ustage7',
            stage8='$ustage8',
            stage9='$ustage9',
            stage10='$ustage10'

            WHERE test_id=1";

Please tell me how this query should be. 请告诉我该查询应该如何。

Form Code - examples of my 2 input fields 表单代码-我的2个输入字段的示例

        <label id="radio-inline"><input type="radio" name="roomTemp" value="warm" <?php if (isset($rtemp) && $rtemp=="warm") echo "checked";?>>&nbsp;Warm</label>
        <label id="radio-inline"><input type="radio" name="roomTemp" value="cool" <?php if (isset($rtemp) && $rtemp=="cool") echo "checked";?>>&nbsp;Cool</label>
        <label id="radio-inline"><input type="radio" name="roomTemp" value="cold" <?php if (isset($rtemp) && $rtemp=="cold") echo "checked";?>>&nbsp;Cold</label>

        <div class="form-group">
        <label class="rateLabel" for="0-3mins">Stage 1<br />5 / 8 (miles/km) ph</label>
        <input type="text" class="form-control" name="txt_stage1" placeholder="HR after 0 - 3 mins" value="<?php if(isset($error)){echo $ustage1;}?>">
        </div>

What is the primary key of the table? 该表的主键是什么? If it has one Ie userid then 如果它具有一个Ie用户ID,则

Replace the second statement by an update statement 用更新语句替换第二条语句

update table2 
set value1=...
from table1
where userid=1

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

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