1

My insert database i have a table named:

table1 with 4 columns

user | id | roll |class

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

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.

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();

?> 
Community
  • 1
  • 1
USERRR5
  • 430
  • 2
  • 10
  • 27

2 Answers2

1

Use update statement in newadd.php instead of insert

1

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

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

Jurij Jazdanov
  • 1,248
  • 8
  • 11