PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 13th, 2012, 10:37 AM
BitZoid's Avatar
BitZoid BitZoid is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 98 BitZoid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 2 h 20 m 38 sec
Reputation Power: 1
MySQL error "Incorrect decimal value: for column rentprice at row 1"

I have an add inventory page where if user clicks rent checkbox, he must enter rentprice - same with sell.

However, I keep getting MySQL error "Incorrect decimal value: for column rentprice at row 1"

MySQL defined as
Column: rentprice DECIMAL(8,2) - Default of NULL
Column: sellprice DECIMAL(8,2) - Default of NULL

Here is my code:
PHP Code:
if ((empty($_POST['rent'])) && (empty($_POST['sell']))) {

$errors[] = 'You must select either Rentable or Sellable checkbox.'
}
if (
$_POST['rent']) {
$rent 1;
     if (
$_POST['rentprice']) {
          
$rentprice $_POST['rentprice'];
    } else { 
$errors[] = 'If you select rentable, you must enter a rental price.';
$rentprice NULL;
}
} else {
$rent 0;     }
if (
$_POST['sell']) {
$sell 1;
if (
$_POST['sellprice']) {
$sellprice $_POST['sellprice'];
} else { 
$errors[] = 'If you select sellable, you must enter a sale price.';
$sellprice NULL
}
} else { 
$sell 0;
}
// Make Query
$queryInsert "INSERT INTO page-mdl (man_key, cls_key, sub_cls_key, model, rent, sell, rentprice, sellprice) VALUES ('$man_key', '$cls_key', '$sub_cls_key', '$model', '$rent', '$sell', '$rentprice', '$sellprice')";
$resultInsert = @mysql_query ($queryInsert); // Run Query 



Oh yeah, and I get this error on the field that is NOT being entered. So If I only enter a Sale Price - It says incorrect decimal on rentprice and vice versa? So I think it has to do with the }else{ clause and the price = NULL or the original if ($_POST['rentprice']) { then }

Reply With Quote
  #2  
Old November 13th, 2012, 12:16 PM
TonyF123 TonyF123 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2007
Location: Purley, Surrey
Posts: 242 TonyF123 User rank is Sergeant Major (2000 - 5000 Reputation Level)TonyF123 User rank is Sergeant Major (2000 - 5000 Reputation Level)TonyF123 User rank is Sergeant Major (2000 - 5000 Reputation Level)TonyF123 User rank is Sergeant Major (2000 - 5000 Reputation Level)TonyF123 User rank is Sergeant Major (2000 - 5000 Reputation Level)TonyF123 User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Month 1 Day 12 h 59 m 53 sec
Reputation Power: 27
echo out $queryInsert so you can see what the query it is trying to run actually is.

Reply With Quote
  #3  
Old November 13th, 2012, 12:30 PM
BitZoid's Avatar
BitZoid BitZoid is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 98 BitZoid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 2 h 20 m 38 sec
Reputation Power: 1
Quote:
Originally Posted by TonyF123
echo out $queryInsert so you can see what the query it is trying to run actually is.


Code:
INSERT INTO model (man_key, cls_key, sub_cls_key, model, rent, sell, rentprice, sellprice, description, video) VALUES ('13', '24', '30', 'A-Test', '1', '0', '69.99', '', 'thisdescrip', 'vidlink')


Ok - This makes me believe that the $sellprice=NULL variable isn't even being reached. It is inside an incorrect if condition - which is blowing my mind right now.

It's only 2 Dimensions deep, but I cannot figure it out.

Reply With Quote
  #4  
Old November 13th, 2012, 12:43 PM
BitZoid's Avatar
BitZoid BitZoid is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 98 BitZoid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 2 h 20 m 38 sec
Reputation Power: 1
Ok I added another variable after the main else clause that defines sellprice and rentprice as 0 instead of NULL (For some reason I cannot insert NULL, but I can 0.

It does work now, but inserts a 0.00 into database for the suppose to be NULL. I Guess I can make my querys read if $row[sellprice] = 0.00 instead of (empty($row[sellprice]))

Reply With Quote
  #5  
Old November 13th, 2012, 01:04 PM
BitZoid's Avatar
BitZoid BitZoid is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 98 BitZoid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 2 h 20 m 38 sec
Reputation Power: 1
I researched jscript to make rentprice and sellprice input text boxes only appear when the rent or sell checkbox is marked, therefor bypassing the entire need to create those secondary if condition checks and null defines.

PHP Code:
<p>Rentable? <input type="checkbox" name="rent" value="1" onclick="showBox(this)">This item is available for Rental</p>
<
p><input type='text' name='rentprice' id='rentprice' value='Rental price per day' style="display:none" />
<
script type="text/javascript">
function 
showBox(elem){
document.getElementById("rentprice").style.display=elem.checked?"block":"none";
}
</script></p>
<p>Sellable? <input type="checkbox" name="sell" value="1" onclick="showBox2(this)">This item is available for Sale</p>
<p><input type='text' name='sellprice' id='sellprice' value='Sale price' style="display:none"/>
<script type="text/javascript">
function showBox2(elem){
document.getElementById("sellprice").style.display=elem.checked?"block":"none";
}
</script></p> 


Elegance born by initial failure.

Reply With Quote
  #6  
Old November 13th, 2012, 06:59 PM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,867 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 22 h 33 m 20 sec
Reputation Power: 813
Hi,

your misconception is that a PHP null will become an SQL NULL. That's not the case. When you put a PHP null into a query string, it gets casted to an empty string (because that's how PHP works). If you want to insert an SQL NULL, you need to explicitly insert the string "NULL" (without the single quotes around it).

You also need to work on the security of your scripts. This one is completely open to SQL injections, allowing everybody to manipulate the query. The mysql_functions are generally obsolete. Choose one of the contemporary extensions.



Quote:
Originally Posted by BitZoid
I researched jscript to make rentprice and sellprice input text boxes only appear when the rent or sell checkbox is marked, therefor bypassing the entire need to create those secondary if condition checks and null defines.


Client-side validations never suffice, because they can simply be bypassed.
Comments on this post
E-Oreo agrees: beat me to it
npl disagrees!

Reply With Quote
  #7  
Old November 13th, 2012, 08:13 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,931 E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 7 h 49 m 26 sec
Reputation Power: 7053
When you cast a NULL value to a string it becomes an empty string (not the PHP string 'NULL'). Thus when you are building a SQL query in PHP, if you want to send a NULL value to MySQL you have to write the PHP string 'NULL' into the query.
__________________
PHP FAQ
How to program a basic, secure login system using PHP

Quote:
Originally Posted by Spad
Ah USB, the only rectangular connector where you have to make 3 attempts before you get it the right way around

Last edited by E-Oreo : November 13th, 2012 at 08:33 PM.

Reply With Quote
  #8  
Old November 13th, 2012, 08:27 PM
ManiacDan's Avatar
ManiacDan ManiacDan is offline
Likely to be eaten by a grue.
Dev Shed God 10th Plane (9500 - 9999 posts)
 
Join Date: Oct 2006
Location: Pennsylvania, USA
Posts: 9,805 ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)ManiacDan User rank is General 77th Grade (Above 100000 Reputation Level)  Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1Folding Points: 127430 Folding Title: Super Ultimate Folder - Level 1
Time spent in forums: 2 Months 3 Weeks 17 h 43 m 13 sec
Reputation Power: 6112
Quote:
Originally Posted by E-Oreo
When you cast a NULL value to a string it becomes an empty string (not the string 'NULL'). Thus when you are building a SQL query in PHP, if you want to send a NULL value to MySQL you have to write the string 'NULL' into the query.
Make sure you don't quote NULL values, 'NULL' is the string 'NULL', 4 characters. NULL by itself, unquotes, is the value null.
Comments on this post
E-Oreo agrees: Good point... let me update that to indicate that the value is a PHP string
__________________
HEY! YOU! Read the New User Guide and Forum Rules

"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

Reply With Quote
  #9  
Old November 13th, 2012, 08:46 PM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Click here for more information.
 
Join Date: Jul 2012
Location: Germany
Posts: 1,867 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 1 Day 22 h 33 m 20 sec
Reputation Power: 813
Already said all that above. But I guess ManiacDan has me on his ignore list?
Comments on this post
npl disagrees: Good for him

Reply With Quote
  #10  
Old November 13th, 2012, 08:52 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Click here for more information.
 
Join Date: Dec 2004
Posts: 7,931 E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)E-Oreo User rank is General 91st Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 7 h 49 m 26 sec
Reputation Power: 7053
No, he was correcting my post because the way I worded it made it sound like you had to enclose the word NULL in single quotes inside the MySQL query in order to send a NULL value to the database.

You did already say all of that in your post, but I had the thread sitting open for a long time and didn't see that you had posted before I did.

Last edited by E-Oreo : November 13th, 2012 at 08:54 PM.

Reply With Quote
  #11  
Old November 13th, 2012, 09:52 PM
BitZoid's Avatar
BitZoid BitZoid is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 98 BitZoid User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 2 h 20 m 38 sec
Reputation Power: 1
Quote:
Originally Posted by Jacques1
Hi,

your misconception is that a PHP null will become an SQL NULL. That's not the case. When you put a PHP null into a query string, it gets casted to an empty string (because that's how PHP works). If you want to insert an SQL NULL, you need to explicitly insert the string "NULL" (without the single quotes around it).

You also need to work on the security of your scripts. This one is completely open to SQL injections, allowing everybody to manipulate the query. The mysql_functions are generally obsolete. Choose one of the contemporary extensions.



This application will be on an intranet, with only a few trusted users able to access it. But I would like to have security as well, so I could use trim($_POST, to prevent injection attempts right?

I have the Jscript handling the problem of data integrity Is this ok? Should I just add trim to var's?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > MySQL error "Incorrect decimal value: for column rentprice at row 1"

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap