Solved

mysql Update a row with WHERE condition

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

752 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