Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

mysql Update a row with WHERE condition

Posted on 2010-08-14
3
Medium Priority
?
326 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 29

Accepted Solution

by:
sammySeltzer earned 500 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 500 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

721 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