Jump to content

Update is resulting in 0!!


ririe44

Recommended Posts

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());
}

?>

Link to comment
https://forums.phpfreaks.com/topic/146816-update-is-resulting-in-0/
Share on other sites

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!

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.