Price override function


#1

I am currently doing a project and have products and prices from a database within a table, and I would like to create a text box which has a function to override the price that is already set in the database for each particular product. Is there any way of doing this?


#2

So, you want a form to change prices in the database?


#3

Basically, yes but it just has to be able to change a price that is already in the database table, I need to be able to override each particular products price and ouput the change in the price field within the table on the site.


#4

You pull the price from a record in the database, to find this record back you need the record-identifier.
You’re going to need a form so you can change the price and then you’ll need a php script that processes the form and updates the record in the database.

You’re going to need a little bit of HTML, PHP and SQL for this. What level of knowledge do you have of these?


#5

I have a limited knowledge of html and php, and a better knowledge of sql. I have so far managed to create a table in dreamweaver that displays the product code, description, standard cost and web cost. I now have a text box where I need to be able to manually type in a new price that will override the web cost that is already in the table. This is where I am in need of a function in order to manually override the price of each individual products web cost if needed.


#6

I see, it’s a little bit more difficult than “Here is your function [download]”.
If you already managed to get Dreamweaver to produce a table with prices and products you may want to use that to produce forms.
For every price you’ll need three(3) elements in every form.

  • a hidden input with the ID ( Or what the identifier of the database record is named ) ( name=“id” )
  • a text input with the price in it. You change the price here ( name=“price” )
  • a submit button to submit this form.
    ( This is a not very elegant but basic way to change one price. changing more prices in one submit is a little more complicated )
    On the server you need a little script that reads these values, turns them into an SQL query and sends that to the database.

It’ll look something like (very crude) %ANCHOR% I use to indicate things I have no idea of their name
[php]

<?php $price = $_REQUEST['price']; $id = $_REQUEST['id']; $sql = "update %TABLE_NAME% set price = '$price' where id = '$id'"; /* And here a codenugget where you kick the query in the direction of your database */ ?>

[/php]( This is a mere example )

That is it. I’m not sitting in your system, so I can’t help you in detail.


#7

Thank you for the help. Would you have a solution for overriding the web cost as I have done the following to calculate the web cost:

<?php echo round ($row_Products['round(StandardCost,2)'] *= 1.40, 2) ; ?>

I need to be able to override the value that is output from this if possible.


#8

That’s a repetition of your initial question, isn’t it?
I’ll just point up 2 messages then. :smiley:


#9

Dreamer123, your post is a little unclear. Are you wanting to update the database with the new prices. OR have some code that uses the following logic: if the override is set then use that on the page which displays the $_POST information instead of the original database information.

if it’s the latter then you need a function in your post script that should look something like this:
[php]
if(isset($_POST[‘overrideprice’])) {
echo $_POST[‘overrideprice’];
} else {
echo $_POST[‘originalprice’];
}
[/php]


#10

Sorry it is not very clear but hopefully this will make things a bit clearer:

My problem is that I am struggling getting a text box input, when a value is manually input, to override and replace the web cost value that has already been calculated and output in the table.

Here is my code for this form:

<?php do { ?> [b]// This is the web cost that I would like to be able to override manually for each product if needed.[/b]
Code Name Standard Cost Web Price Override
<?php echo $row_Products['Code']; ?> <?php echo $row_Products['Name']; ?> £<?php echo $row_Products['round(StandardCost,2)']; ?> £<?php echo round ($row_Products['StandardCost'] *= 1.40, 2) ; ?>£ [b]// This is the text box and submit button (below) that I plan to use for this function.[/b]
    <input type="submit" name="Override2" id="Override2" value="Submit" />
    </label></td>
</tr>
<?php } while ($row_Products = mysql_fetch_assoc($Products)); ?>

Hopefully this makes what I am aiming to achieve clearer?


#11

By web cost I am meaning web price


#12

I have now decided to use a different method for this function, however I now need help getting the value input into the text box to store itself in the text box, and also would like text stating that a price has been updated once the update button has been pressed.

Here is my code for this so far:

/> // Text box for manual override of prices. Would like the value that is input by the user to be stored here so that it is visible when changed

// The update button


#13

What’s different about this method ? I only see output reformatted.

[php]<?php
if ( array_key_exists( ‘webprice’, $_REQUEST ) && array_key_exists( ‘product_id’, $_REQUEST ) )
{ $price = $_REQUEST[‘webprice’];
$id = $REQUEST[‘product_ic’];
$query = “update %THATVAGUETABLEYOUHAVENTMENTIONEDYET% set webprice=’$price’ where %THEPRODUCTIDENTIFIERYOUREALLYNEEDTOUPDATE% = ‘$id’”;
mysql_query( $query ) or die( “Huh? MySQL? Why? Error:”. mysql_error() );
}
?>[/php]

And that should update the value in the database.
Is that what you were looking for?


#14

Yes that was what I was looking for thank you very much for the help much appreciated


#15

And so you reformat the question and ask it yet again?
:o
http://www.phphelp.com/forum/index.php?topic=16112.msg52762#msg52762

I actually gave you the update statement above.
You say

I have a limited knowledge of html and php, and a better knowledge of sql.

Then obviously I haven’t been very clear. Please explain what part you didn’t understand so I can try and be more helpful.

Thanks!
O.