Solved

mysql Update a row with WHERE condition

Posted on 2010-08-14
3
313 Views
Last Modified: 2013-12-13
MySQL

How do I update all the columns in a row using the WHERE clause? the WHERE is equal to a php variable.

thanks.
0
Comment
Question by:Solutionabc
3 Comments
 
LVL 4

Expert Comment

by:philkeene
ID: 33437944
The UPDATE statement is used in the following way...

UPDATE mytable SET myfield = 'newvalue' WHERE myotherfield = 'a value'

... if you need to update all rows, simply miss off from WHERE onwards.

... hope this helps...
0
 
LVL 28

Accepted Solution

by:
sammySeltzer earned 125 total points
ID: 33437977
hi,

Pass the variables:

  $var1 = $_POST['var1'];
  $var3 = $_POST[var3 ];
  $var3 = $_POST[var3 ];
  $var3 = $_POST[var3 ];
  $var3 = $_POST[var3 ];
  $someid = $_POST[someid ];

etc,
etc

then the update code:

$query = "update tablename" set field1='$var1,field2='$var2',field3='$var3,field4='$var4 where id='$someId" ;
      $result = mysql_query($query);' " ;

Something like this.

If you have more questions or if you want to attempt it and post the code, please do so
0
 
LVL 4

Assisted Solution

by:thor_victor
thor_victor earned 125 total points
ID: 33438736
Both are right. But....

UPDATE table SET field1 = 'var1', field2 = 'var2' WHERE field3 = 'var3';

i WOULD ADD = LIMIT 1 (or the number of spected rows to be changed cuz in a simple error, you could affect all rows)

UPDATE table SET field1 = 'var1', field2 = 'var2' WHERE field3 = 'var3' LIMIT 1;
0

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now