mysql help ?
Moderator: General Moderators
-
adilmarwat2004
- Forum Commoner
- Posts: 44
- Joined: Fri Sep 04, 2009 11:28 pm
mysql help ?
I have mysql table named "act" contain fields:-
id, name, pay, allowances, total_salary
I want that when i amount of pay field & allowances field should add and display in total_salary field. How it is possible.
Please help me in serious matter.
thanks
Adil
id, name, pay, allowances, total_salary
I want that when i amount of pay field & allowances field should add and display in total_salary field. How it is possible.
Please help me in serious matter.
thanks
Adil
Re: mysql help ?
I realize that English is not your first language but your question is very confusing. Please clarify.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: mysql help ?
Something like:adilmarwat2004 wrote:I have mysql table named "act" contain fields:-
id, name, pay, allowances, total_salary
I want that when i amount of pay field & allowances field should add and display in total_salary field. How it is possible.
Please help me in serious matter.
thanks
Adil
Code: Select all
INSERT INTO act (`name`, `pay`, `allowances`, `total_salary`) VALUES ('$name', $pay, $allowances, $pay+$allowances)mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: mysql help ?
You're almost right - Try this:AbraCadaver wrote:Something like:adilmarwat2004 wrote:I have mysql table named "act" contain fields:-
id, name, pay, allowances, total_salary
I want that when i amount of pay field & allowances field should add and display in total_salary field. How it is possible.
Please help me in serious matter.
thanks
Adil
Code: Select all
INSERT INTO act (`name`, `pay`, `allowances`, `total_salary`) VALUES ('$name', $pay, $allowances, $pay+$allowances)
Code: Select all
INSERT INTO act (name, pay, allowances, total_salary) VALUES ('$name', '$pay', 'allowances', '$pay'+'$allowances')- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: mysql help ?
I agree with not storing a calculated value, however stating that I was almost right when it was entirely right was strange. Quotes aren't needed for numeric values and are normally used to prevent SQL injection attacks which you should take care of with a real_escape_string() / type casting / filtering etc. before insert.
Also, with your insert, every row will have 0 for `allowances` field because you passed in the literal text 'allowances' instead of the value of $allowances
Also, with your insert, every row will have 0 for `allowances` field because you passed in the literal text 'allowances' instead of the value of $allowances
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: mysql help ?
LOL - you didn't have quotes around all of your variables thoughAbraCadaver wrote:I agree with not storing a calculated value, however stating that I was almost right when it was entirely right was strange. Quotes aren't needed for numeric values and are normally used to prevent SQL injection attacks which you should take care of with a real_escape_string() / type casting / filtering etc. before insert.
Also, with your insert, every row will have 0 for `allowances` field because you passed in the literal text 'allowances' instead of the value of $allowances
Ah! And I missed a $. Too funny!
I did such a quick read on that, I thought it was the query string from the original poster. I saw the missing quotes and corrected (and made more mistakes).
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: mysql help ?
That was my point. I had quotes around the value for the text field. They're not needed for numeric data, and I assumed that monetary amounts would be stored in a numeric field.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Re: mysql help ?
Maybe I'm confused (i am fairly new at this) but aren't quote marks required around all variables regardless of data type?AbraCadaver wrote:That was my point. I had quotes around the value for the text field. They're not needed for numeric data, and I assumed that monetary amounts would be stored in a numeric field.
- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: mysql help ?
Nope. You should always quote text/varchar etc... but they will normally insert without them unless they contain a space. Now it can help against SQL injection, but if you are inserting a number you should have already checked/casted it: $id = (int)$_POST['id']; etc.JakeJ wrote:Maybe I'm confused (i am fairly new at this) but aren't quote marks required around all variables regardless of data type?AbraCadaver wrote:That was my point. I had quotes around the value for the text field. They're not needed for numeric data, and I assumed that monetary amounts would be stored in a numeric field.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.