Solved

mysql Update a row with WHERE condition

Posted on 2010-08-14
3
310 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
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 …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

744 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

12 Experts available now in Live!

Get 1:1 Help Now