Page 1 of 1

mysql ... adding a field on update query ...

Posted: Tue Mar 30, 2010 2:56 pm
by pepe_lepew1962
Hello:

Okay, there has to be a simple answer that is beyond me on this. During an UPDATE, I would like to add a variable to a field. In example here, simply add the variable $varpepe101 to the contents of field pepe_99. Everything is and will be characters, this is not numeric in any way. Can someone show me where I am making my mistake please.


// Assign table to variable.
$varpepe101 = "P";
//
//
// Insert data from table where row that match this passkey.
$sql = mysql_query("UPDATE tblPepe SET pepe_99 = pepe_99.$varpepe101 WHERE tblPepe11 = 'ABC'");

Re: mysql ... adding a field on update query ...

Posted: Tue Mar 30, 2010 3:13 pm
by AbraCadaver
Assuming that tblPepe11 is a field in the table and at least one row contains ABC:

Code: Select all

$sql = mysql_query("UPDATE tblPepe SET pepe_99 = '$varpepe101' WHERE tblPepe11 = 'ABC'");

Re: mysql ... adding a field on update query ...

Posted: Tue Mar 30, 2010 3:17 pm
by pepe_lepew1962
Actually, I want to combine or add the contents of the field. So if the field had HWTY in it, simple append or add the variable to the end of it, in this case, making it HWTYP.

Re: mysql ... adding a field on update query ...

Posted: Tue Mar 30, 2010 3:25 pm
by AbraCadaver

Code: Select all

$sql = mysql_query("UPDATE `tblPepe` SET `pepe_99` = CONCAT(`pepe_99`, '$varpepe101') WHERE `tblPepe11` = 'ABC'");

Re: mysql ... adding a field on update query ...

Posted: Tue Mar 30, 2010 3:35 pm
by pepe_lepew1962
Yup, that did it, thank you.