从两个不同的phpfile将数据插入到同一个表中

时间:2022-06-21 01:06:21

My insert database i have a table named:

我的插入数据库我有一个名为的表:

table1 with 4 columns

table1有4列

user | id | roll |class

用户| id |滚|班

I have 2 php files table1.php and newadd.php. I have inserted user, id, class value in table1 via table1.php.

我有2个php文件table1.php和newadd.php。我已经通过table1.php在table1中插入了user,id,class值。

I want to insert class value in same table via newadd.php, but when I run the files from localhost values are inserted perfectly, but in different row, not in same row.

我想通过newadd.php在同一个表中插入类值,但是当我从localhost运行文件时,值完全插入,但是在不同的行中,而不是在同一行中。

My query is:

我的查询是:

INSERT INTO table1 (class) VALUES ('two') WHERE id=123;

but it is not working..what should i do?

但它不起作用......我该怎么办?

Here is my code

这是我的代码

<?php
    include('insertjoincon.php');
    if ($conn->connect_error) {
        die("Connection failed: " . $conn->connect_error);
    }

    $sql = "INSERT INTO table1 (class)
    VALUES ('two') WHERE id=123";

    if ($conn->query($sql) === TRUE) {
     echo "New record created successfully";
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }

    $conn->close();

?> 

2 个解决方案

#1


INSERT makes a new row, but you need to change the already exicting one

INSERT会创建一个新行,但您需要更改已经存在的行

"UPDATE table1 SET class='two' WHERE id=123";

“UPDATE table1 SET class ='two'WHERE id = 123”;

#2


Use update statement in newadd.php instead of insert

在newadd.php中使用update语句而不是insert

#1


INSERT makes a new row, but you need to change the already exicting one

INSERT会创建一个新行,但您需要更改已经存在的行

"UPDATE table1 SET class='two' WHERE id=123";

“UPDATE table1 SET class ='two'WHERE id = 123”;

#2


Use update statement in newadd.php instead of insert

在newadd.php中使用update语句而不是insert