master82 Posted March 7, 2006 Share Posted March 7, 2006 Hello, (first post so hopefully someone will help me)I've got a MYSQL database with the table 'Users'Within this is the field 'Sales'I have created a simple HTML form that allows me to input a number and submit it (simple stuff!) (and told it to run salesupdate.php once submitted)NOW, im stuck trying to create the 'salesupdate.php' that will do the following:1. Retrieve the submitted number from the HTML form ($_POST['sales'] if im correct?) [eg 10]2. Retrieve the number already contained within the database [eg 25]THEN (if possible)3a. multiply the submitted number by 0.75 [eg 10*0.75 = 7.5] and then add this to the number in the database [eg 7.5 + 25 = 32.5 in the field]OR (if not possible above)3b. Simple take the value from the submitted and the database and add them together, replacing the old database number.Thanks in advance Quote Link to comment Share on other sites More sharing options...
dcro2 Posted March 7, 2006 Share Posted March 7, 2006 You could:[code]$sql = mysql_query("SELECT * FROM Users WHERE user_id = '$userid'"); //I'm just guessing about the user_id.$row = mysql_fetch_assoc($sql);$finalnumber = intval($_POST['sales']) * (0.75);$finalnumber = $finalnumber + intval($row['num_field']);$sql = mysql_query("UPDATE Users SET num_field = '$finalnumber'");if($sql) { echo "Success!";} else { echo "Failed...";}[/code]Of course, replace 'num_field' with the field in your database. Quote Link to comment Share on other sites More sharing options...
master82 Posted March 7, 2006 Author Share Posted March 7, 2006 Thanks for that speedy reply :)I added the essentials such as PHP tags and connection string and tested. It ran and produced the success! message, however it replaced the value in the table to 0.Could someone please look at the code I tried - I think there is a problem with lines 8 & 9 as they are both $finalnumber. (can I change the 2nd to $finalnum, and the one on line 11 too? - think i'll test that, also go back to my HTML form see if an error lies there).Anyone spot anything wrong here?[code]<?php$conn = mysql_connect("localhost", "username", "password");mysql_select_db("database",$conn);$sql = mysql_query("SELECT * FROM Users");$finalnumber = intval($_POST['sales']) * (0.75);$finalnumber = $finalnumber + intval($row['SalestoDate']);$sql = mysql_query("UPDATE Users SET SalestoDate = '$finalnumber'");if($sql) { echo "Success!";} else { echo "Failed...";}?>[/code] Quote Link to comment Share on other sites More sharing options...
master82 Posted March 7, 2006 Author Share Posted March 7, 2006 FIXED!!! was a problem with the HTML form I created and the two $finalnumber.Thanks for your help :) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.