Jump to content

How do I update a specific row in my MySQL db with PHP?


Guest kilbad

Recommended Posts

Guest kilbad
I have been trying to learn how to use mysql, somewhat successfully, using an online tutorial. However, I cannot figure out how to code a php script that will allow me to update specific rows (based on the ID number) in my mysql db.  Can someone help me out by posting some code to get me started?  I can then probably take it from there, and/or reply if I have further questions.

The tutorial I was using (and step I got stuck on) is located at: http://www.freewebmasterhelp.com/tutorials/phpmysql/7

Thank you so much in advance.

Brendan

Link to comment
Share on other sites

had 2min to spere good luck

[code]
<?php

$db=mysql_connect("localhost","xxx","xxx");
mysql_select_db("database_name",$db);

$query_update="update xxxxxxxx set hits='xxxx' where xxxx='xxxxxx' ";
$result_query=mysql_query($query_update);

?>
[/code]

Hope this helps everyone ok.
[code]

<?php

Select Statement
SELECT "column_name" FROM "table_name"

Distinct
SELECT DISTINCT "column_name"
FROM "table_name"

Where
SELECT "column_name"
FROM "table_name"
WHERE "condition"

And/Or
SELECT "column_name"
FROM "table_name"
WHERE "simple condition"
{[AND|OR] "simple condition"}+

In
SELECT "column_name"
FROM "table_name"
WHERE "column_name" IN ('value1', 'value2', ...)

Between
SELECT "column_name"
FROM "table_name"
WHERE "column_name" BETWEEN 'value1' AND 'value2'

Like
SELECT "column_name"
FROM "table_name"
WHERE "column_name" LIKE {PATTERN}

Order By
SELECT "column_name"
FROM "table_name"
[WHERE "condition"]
ORDER BY "column_name" [ASC, DESC]

Count
SELECT COUNT("column_name")
FROM "table_name"

Group By
SELECT "column_name1", SUM("column_name2")
FROM "table_name"
GROUP BY "column_name1"

Having
SELECT "column_name1", SUM("column_name2")
FROM "table_name"
GROUP BY "column_name1"
HAVING (arithematic function condition)

Create Table Statement
CREATE TABLE "table_name"
("column 1" "data_type_for_column_1",
"column 2" "data_type_for_column_2",
... )

Drop Table Statement
DROP TABLE "table_name"

Truncate Table Statement
TRUNCATE TABLE "table_name"

Insert Into Statement
INSERT INTO "table_name" ("column1", "column2", ...)
VALUES ("value1", "value2", ...)

Update Statement
UPDATE "table_name"
SET "column_1" = [new value]
WHERE {condition}

Delete From Statement
DELETE FROM "table_name"
WHERE {condition}

?>
[/code]
Link to comment
Share on other sites

Okay, to give you a specific exemple of an update:

UPDATE my_table SET column_a = 'abc' WHERE id = 0

Change column_a to value 'abc' for every row in table my_table where column id contains the value 0.
assuming that column_a is a character type column and column id is a numeric type column.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.