Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace multiple fields in active record with one variable

Status
Not open for further replies.

keepingbusy

Programmer
Apr 9, 2000
1,470
GB
Hello

Not sure how to do this in php, but what I am trying to achieve is to replace several fields in a record with a single variable.

For example, if I had price1, price2, price3, price4 etc and wanted to replace them with a value stored in newprice that has been entered into a field by me, how could I do that?

I see there is a command called INSERT but that adds a record to the table.

From a FoxPro point of view I would do this by saying:
Code:
replace price1, price2, price3, price4 with newprice
which is fairly straight forward.

I would either like to do this via a command button in php or a hyperlink, it makes no difference.

If you need more information please let me know and some guidance not the sollution would be most advantageous.

Thank you


Windows Vista
Visual FoxPro Versions 6 & 9
 
Where is this record coming from? a Database if so which one: MYSQL, MSSQL, ORACLE etc...?
A file? an array maybe?

You need to tell us more about your record and how you are accessing it before we can suggest an approach.

If this is a database:

Look at the Update statement syntax for the DB you are using.





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
The record is being accessed from a MySQl database. It is part of a procedure that we access the record to change details in an administrator mode. The records has multiple price fields as mentioned and I just need to be able to enter a single price in one field and then click on something so it forces the other selected fields to be populated with that price I have entered.

Does that help?

Windows Vista
Visual FoxPro Versions 6 & 9
 
I've also found this:
Code:
UPDATE my_table SET `my_field` = replace(`my_field`, "old_text", "new_text")
So if this is the command:

1. How would I add additional fields?
2. How do I ensure that the correct record is updated?
3. How can I implement this process via a command button

Thank you

Windows Vista
Visual FoxPro Versions 6 & 9
 
O.k so first we need the html for the textbox and the button:

Code:
<form action="process.php" method="POST">
<input type="text" name="price" value="">
<input type="submit" name="send" value="Update Price">
</form>

This creates an HTML form to receive your input. And has a button to press. Once pressed it will execute the PHP, and update your database table with the value you set.

For the PHP:

Code:
if(isset($_POST['send'])){ [green]\\check to see if form is submitted, and perform desired tasks if it was submitted[/green]

$value=mysql_real_escape_string($_POST['price']); [green]\\Prepare and cleanse value for usage in a query[/green]

$query="UPDATE [red]mytable[/red] SET field1=$value, field2=$value, field3=$value ... WHERE [blue]x=y[/blue]"; [green]\\Create Update statement to feed to Database. you can keep adding as many fields as you need to have the same value provided they are all in the same table. There Where class. determines which row(s) from the table should be updated with the new value.  Its a condition. If you remove it it will update every row in the table with the values.[/green]

$res=mysql_query($query) or die(mysql_error()); [green]\\Execute query[/green]

}

This code assumes you've already created the connection to the DB prior to this.





----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Vacunita

Thank you for the very helpful advice and coding. I'll add this to our existing code and post back over the next few days.

Kind regards

Windows Vista
Visual FoxPro Versions 6 & 9
 
I have changed the code to match the table name and field name but could you please explain the concept of
Code:
 ... WHERE x=y";
Is this something to do with the actual record number?

I notice in the table concerned there is a product_id, is this what it means and how do I match it?

Thank you

Windows Vista
Visual FoxPro Versions 6 & 9
 
Yes, that is pretty much correct.
what you use to identify yout record only you know. since I have no knowledge of your table structure.

If you know before hand the id of the record you want to modify, you can set to the value. sayÑ

WHERE column_id=2345

Assuming your table has a field named column_id and one of the rows has a value of 2345 for the column_id field. And that is the one you want to update.




----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top