ririe44 Posted February 25, 2009 Share Posted February 25, 2009 So, I have this update code to update a simple budget on a database. I've gone through the code a number of times and I can't figure out why it always changes my requested modifications to zero! So, the field is set to $45, I'll type in $49... and it sets it to $0. What do you think... my database field is set to decimal(65,2). I've checked my source code, and I'm updating the correct field in the database.... any ideas? Thanks! Here's my code (i've removed database info): budg_retrieve.php <? include("checksession.php"); $host="host"; // Host name $db_username="username"; // Mysql username $db_password="password"; // Mysql password $db_name="name"; // Database name $tbl_name="budget"; // Table name // Connect to server and select databse. mysql_connect("$host", "$db_username", "$db_password")or die(mysql_error()); mysql_select_db("$db_name")or die(mysql_error()); $budg_data = mysql_query("SELECT * FROM `$tbl_name`") or die(mysql_error()); Print "<form action=budg_update.php>"; Print "<table border cellpadding=3>"; Print "<tr>"; Print "<th>Category</th> <th>Sub-Category</th> <th>Amount</th> <th>Edit</th></tr>"; while($info = mysql_fetch_array( $budg_data )) { Print "<tr>"; Print "<td>".$info['category'] . "</td> "; Print "<td>".$info['sub_category'] . "</td> "; Print "<td>$".$info['amount'] . "</td>"; Print "<td><input type='text' name='".$info['sub_category']."' value='".$info['amount']."'</td></tr>"; } Print "<tr>"; Print "<td colspan=4 align=center><input type='submit' name='submit' value='Update'></td>"; Print "</table>"; Print "</form>"; ?> budg_update.php <? $host="host"; // Host name $db_username="username"; // Mysql username $db_password="password"; // Mysql password $db_name="name"; // Database name $tbl_name="budget"; // Table name // Connect to server and select databse. mysql_connect("$host", "$db_username", "$db_password")or die(mysql_error()); mysql_select_db("$db_name")or die(mysql_error()); $budg_mortgage = $_POST['Mortgage']; $budg_hoa = $_POST['HOA']; $budg_mustang = $_POST['Mustang']; $budg_vulcan = $_POST['Vulcan']; $budg_school = $_POST['School']; $budg_auto_gas = $_POST['Auto Gas']; $budg_auto_insurance = $_POST['Auto Insurance']; $budg_auto_maintenance = $_POST['Auto Maintenance']; $budg_internet = $_POST['Internet']; $budg_electricity = $_POST['Electricity']; $budg_gas = $_POST['Gas']; $budg_cell_phones = $_POST['Cell Phones']; $budg_home_insurance = $_POST['Home Insurance']; $budg_home_maintenance = $_POST['Home Maintenance']; $budg_groceries = $_POST['Groceries']; $budg_dining_out = $_POST['Dining Out']; $budg_pets = $_POST['Pets']; $budg_investments = $_POST['Investments']; $budg_newspaper = $_POST['Newspaper']; $budg_medical = $_POST['Medical']; $budg_diapers = $_POST['Diapers']; $budg_baby_sitting = $_POST['Baby Sitting']; $budg_movies = $_POST['Movies']; $budg_clothing = $_POST['Clothing']; $budg_gifts = $_POST['Gifts']; $budg_savings = $_POST['Savings']; $budg_books = $_POST['Books']; $budg_crafts = $_POST['Crafts']; $budg_entertainment = $_POST['Entertainment']; $budg_vacation = $_POST['Vacation']; $budg_school = $_POST['School']; $query = "UPDATE `$tbl_name` SET `amount` = '$budg_mortgage' WHERE `sub_category` = 'Mortgage'"; if (mysql_query($query)) { echo "Your budget has been updated! <br> Would you like to make another modification? <a href='budg_retrieve.php'>Yes</a>"; }else { die(mysql_error()); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/146816-update-is-resulting-in-0/ Share on other sites More sharing options...
dropfaith Posted February 25, 2009 Share Posted February 25, 2009 first things first if you echo $budg_mortgage does it echo 0 or the correct data Quote Link to comment https://forums.phpfreaks.com/topic/146816-update-is-resulting-in-0/#findComment-770798 Share on other sites More sharing options...
ririe44 Posted February 25, 2009 Author Share Posted February 25, 2009 hmm... it doesn't echo anything, so I'm guessing its 0. Interesting... what do you think? Quote Link to comment https://forums.phpfreaks.com/topic/146816-update-is-resulting-in-0/#findComment-770803 Share on other sites More sharing options...
Philip Posted February 25, 2009 Share Posted February 25, 2009 echo $_POST['Mortgage']... you might be calling the wrong field name from the form If it doesn't echo anything, then add this above $budg_mortgage = $_POST['Mortgage']; echo '<pre>'; print_r($_POST); echo '</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/146816-update-is-resulting-in-0/#findComment-770809 Share on other sites More sharing options...
ririe44 Posted February 25, 2009 Author Share Posted February 25, 2009 This is what I get with the <pre>... Array ( ) Your budget has been updated! Would you like to make another modification? But the data is still 0... Quote Link to comment https://forums.phpfreaks.com/topic/146816-update-is-resulting-in-0/#findComment-770830 Share on other sites More sharing options...
ririe44 Posted February 25, 2009 Author Share Posted February 25, 2009 SOLVED! Ha, I'm dumb... thanks to everyone for your help! As I was going through it again, I noticed on my form tag that I didn't have "method=post"!!!! So, nothing was being posted. I fixed that and it works great. Hopefully the other parts of this thread can be educational to others, they sure were for me! Quote Link to comment https://forums.phpfreaks.com/topic/146816-update-is-resulting-in-0/#findComment-771287 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.