简体   繁体   中英

SQL INSERT INTO for specific cell

I'm trying to use this to insert the value "yes" into the list_title column where stream_number='3'. I can't figure out why it won't actually insert "yes" into the cell or any cell at all for that.

mysqli_query($con,"INSERT INTO livestreams (list_title) VALUE ('yes') WHERE stream_number='3'");

Heres the SQL i'm using to create the table if this helps

$createTable = "CREATE TABLE livestreams (stream_number INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(stream_number), stream_name CHAR(30), desired_username CHAR(30), stream_status CHAR(10), channel_description VARCHAR(300), game_name VARCHAR(100), viewer_count INT, list_title CHAR(30))";

What you're looking for is an UPDATE , not an INSERT . An INSERT adds new rows, while UPDATE changes something within existing rows.

UPDATE livestreams SET list_title = 'yes' WHERE stream_number = '3'

That SQL query should do.

INSERT inserts a new row into the table.
To update an existing row , use an UPDATE query.

Apparently you need to stop thinking in terms of Excel "cells". Databases work with rows aka records , and these records have fields . The datastore is not a 2D grid where you "insert" data into "cells"; even though it is often presented like that in the UI.

You should not use INSERT INTO with WHERE . Use UPDATE instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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