0

I have folliwing PHP file

which is creating this table:

Table createb by PHP with MySQL data

Every row have two inputs. My DB table has AUTO_INCREMENT 'ID' field.

How can I update my DB Table and make sure that rows will be updated accordingly to the ID's (auto incremented field)?

I'm must admit that SQL with PHP is very new to me and I don't know is this correct way of doing it?

            $news_SQLupdate = "UPDATE news SET ";   // table name is 'news'     
            $news_SQLupdate .=  "LIVE= '".$LIVE."', ";
            $news_SQLupdate .=  "CONTENT= '".$CONTENT."', ";
            $news_SQLupdate .=  "WHERE ID = '".$ID."' "; 

5 Answers 5

2

By including the id in the WHERE clause?

UPDATE <someTable> SET ... WHERE id = <someId>
Sign up to request clarification or add additional context in comments.

Comments

0

In your update statement, you will need a where id=(the id number)

Simple example:

UPDATE table_name set field1=value1 where id=1

Comments

0
UPDATE `tblContent` SET `On/Off` = true WHERE (`ID` = 1 OR `ID` = 2)

Dynamicaly add a OR ID = X in the where clause to apply the changes to another record.

Comments

0

"UPDATE table_name SET column_name1=' value[$array]', column_name2=' value[$array]' WHERE column_name=' value[$array]' ";

Comments

0

I tried this one state above:

UPDATE table_name 
SET column_name1=' value[$array]', 
    column_name2=' value[$array]' 
WHERE column_name=' value[$array]' ; 

Just confirming that it worked for me perfectly.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.