Jump to content

Need Help Updating Database


pghtech

Recommended Posts

First off, I am not PHP coder, nor have I ever coded to update database records.  I am in need of adjusting some code in my shopping cart but can't seem to get the right code to update the database directly.  So far I have only been able to successfully create code that calculates a number and updates a text field and the html form updates the database field.

 

I have the below code that creates 4 text boxes.  3 of which retain the dimensions of a box (length, width, height).  The 4th retains the cubic weight of those dimensions (length x width x height).  However, I have not figured out how to update the database IF it finds that these first 3 fields are filled out. 

 

What happens is, if you input L, W, and H, it will calculate the cubic weight and put it in the cubicWeight text box upon clicking the "submit" button on the page the first time, but you have to access the page again and click submit for the "cubicWeight" field in the database to be updated.

 

MY GOAL:

Upon clicking 'submit' the first time, it will determine if there is data in all three fields (Length, Width and Height) and calculate the cubic weight and update the cubicWeight database field (I assume having to use the 'UPDATE' function. 

 

Info:

Specific text fields code:

<td class="tdText"><input name="length" type="text" class="textbox" size="10" value="<?php if(isset($results[0]['length'])) echo $results[0]['length']; ?>" /> L <input name="width" type="text" class="textbox" size="10" value="<?php if(isset($results[0]['width'])) echo $results[0]['width']; ?>" /> W <input name="height" type="text" class="textbox" size="10" value="<?php if(isset($results[0]['height'])) echo $results[0]['height']; ?>" /> H <strong style="padding:0px 10px">Cubic Weight</strong><input name="cubicWeight" type="text" class="textbox" size="10" value="<?php if(isset($results[0]['cubicWeight'])) echo $results[0]['cubicWeight'] = round((($results[0]['length'] * $results[0]['width'] * $results[0]['height']) / 194), 0); ?>" /> <?php echo $config['weightUnit']; ?></td>

 

 

Here is a snippet of database interaction by the PHP code to give some details about the database.  If I am correct on my terminology, the table is named "CubeCart_inventory", and the field/record I have created is called "cubicWeight"

 

$query = sprintf("UPDATE %sCubeCart_inventory SET `cat_id`='%d' WHERE `productId`='%d';", $glob['dbprefix'], $_POST['MoveTo'], $product_id);
	$db->misc($query);

 

Just to clarify, the $query line above is just a reference to interactions with the database, as I don't believe I would be using the 'cat_id' or 'productId' fields for my Update statement.

Link to comment
https://forums.phpfreaks.com/topic/139519-need-help-updating-database/
Share on other sites

  • 3 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.