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 February 13th, 2013, 05:52 PM
jlewis01's Avatar
jlewis01 jlewis01 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 234 jlewis01 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 16 h 8 m 56 sec
Reputation Power: 10
Turn an number negative

I am sure this is fairly simple but I am not getting it. I need disQty to be negative. The user using the preceding, simple, html from must input a positive number. Any help please.

PHP Code:
if(isset($_POST['disQty']))
{
   
$disQty $_POST['disQty'];
   
$pulledItem $_POST['pulledItem'];
   
$n        count($disQty);
   
$i        0;
   while (
$i $n)
   {
$dbh=mysql_connect ($data_base_connection$user$password) or die ('I cannot connect to the database because: ' mysql_error());
mysql_select_db ("hmsglobal");
$result=mysql_query("INSERT INTO exchInv (exchInvItemID,exchQty) VALUES ('{$pulledItem[$i]}','{$disQty[$i]}')")or die("Insert Error: ".mysql_error());
mysql_close;
$date addslashes($date);
      
$i++;
   }



Reply With Quote
  #2  
Old February 13th, 2013, 06:36 PM
E-Oreo's Avatar
E-Oreo E-Oreo is offline
Lost in code
Dev Shed God 7th Plane (8000 - 8499 posts)
 
Join Date: Dec 2004
Posts: 8,057 E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)E-Oreo User rank is General 92nd Grade (Above 100000 Reputation Level)  Folding Points: 945 Folding Title: Novice Folder
Time spent in forums: 2 Months 1 Day 6 h 4 m 32 sec
Reputation Power: 7104
Multiply the value by -1. You can't perform multiplication inside {} in a string, you need to use normal concatenation instead; ie "string" . (expression) . "string"

FYI Your code contains SQL injection vulnerabilities.
__________________
PHP FAQ
How to program a basic, secure login system using PHP
Connect with me on LinkedIn


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

Reply With Quote
  #3  
Old February 13th, 2013, 09:07 PM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 2012
Location: Germany
Posts: 2,042 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 3 Weeks 41 m 33 sec
Reputation Power: 812
Quote:
Originally Posted by E-Oreo
FYI Your code contains SQL injection vulnerabilities.


... and several other bad practices like this "or die()" stuff and reconnecting to the database for every single row (why do you even do that?).

Check the link in my signature and throw away whatever tutorial or book you got those code patterns from.

Reply With Quote
  #4  
Old February 13th, 2013, 09:11 PM
jlewis01's Avatar
jlewis01 jlewis01 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 234 jlewis01 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 16 h 8 m 56 sec
Reputation Power: 10
Quote:
Originally Posted by E-Oreo
Multiply the value by -1. You can't perform multiplication inside {} in a string, you need to use normal concatenation instead; ie "string" . (expression) . "string"

FYI Your code contains SQL injection vulnerabilities.


Okay, I have tried this and it is still positive.

INSERT INTO exchInv (exchInvItemID,exchQty) VALUES ('{$pulledItem[$i]}','$disQty[$i] * -1')

Reply With Quote
  #5  
Old February 13th, 2013, 09:17 PM
jlewis01's Avatar
jlewis01 jlewis01 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 234 jlewis01 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 16 h 8 m 56 sec
Reputation Power: 10
Quote:
Originally Posted by Jacques1
... and several other bad practices like this "or die()" stuff and reconnecting to the database for every single row (why do you even do that?).

Check the link in my signature and throw away whatever tutorial or book you got those code patterns from.


Okay thank you for the feedback. Ill make some changes but in the case of reconnecting to the database what has happened before is a never ending loop inserting the first row until the database with my isp shuts down.

Reply With Quote
  #6  
Old February 13th, 2013, 09:29 PM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 2012
Location: Germany
Posts: 2,042 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 3 Weeks 41 m 33 sec
Reputation Power: 812
Quote:
Originally Posted by jlewis01
Okay, I have tried this and it is still positive.


Have you read what E-Oreo said about string concatenation and that you can't do multiplication inside a string?



Quote:
Originally Posted by jlewis01
Ill make some changes but in the case of reconnecting to the database what has happened before is a never ending loop inserting the first row until the database with my isp shuts down.


Well, then you should fix that rather than use strange workarounds. Going through the whole start-up procedure again and again is a performance killer and also stresses your server, so it's really not something you should have in your code.

What you could try is build the query up and then insert all values at once.

Reply With Quote
  #7  
Old February 13th, 2013, 09:41 PM
jlewis01's Avatar
jlewis01 jlewis01 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 234 jlewis01 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 16 h 8 m 56 sec
Reputation Power: 10
Quote:
Originally Posted by Jacques1
Have you read what E-Oreo said about string concatenation and that you can't do multiplication inside a string?





Well, then you should fix that rather than use strange workarounds. Going through the whole start-up procedure again and again is a performance killer and also stresses your server, so it's really not something you should have in your code.

What you could try is build the query up and then insert all values at once.


Oh okay, I will do that. I did read what E-Oreo said and I got it but just didn't get it. I did however figure it out by your re-explanation. Code listed below. Also, is trigger_error is more acceptable rather than or die?

PHP Code:
 INSERT INTO exchInv (exchInvItemID,exchQtyVALUES ('{$pulledItem[$i]}','$disQty[$i]' *-1

Last edited by jlewis01 : February 13th, 2013 at 09:43 PM.

Reply With Quote
  #8  
Old February 13th, 2013, 10:20 PM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 2012
Location: Germany
Posts: 2,042 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 3 Weeks 41 m 33 sec
Reputation Power: 812
Quote:
Originally Posted by jlewis01
Also, is trigger_error is more acceptable rather than or die?


Yes! Because that actually generates an error, which can be turned off later, redirected to a log file etc.

A die() just dumps its output on the page, not matter if it's you testing the code on your local server or your users visiting your live site. Query errors expose a lot of the internal database code, so they can be used to launch attacks specifically on weak parts of the code.

In conjunction with the injection vulnerabilities (which are still there), I fear your website wouldn't last very long. There are automated tools for this, so it doesn't even have to be a genius "hacker".

Reply With Quote
  #9  
Old February 14th, 2013, 07:44 AM
jpietrangelo jpietrangelo is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2012
Posts: 6 jpietrangelo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 16 m 11 sec
Reputation Power: 0
Pos to Neg

Why not just convert it when you read in the positive number? Like so:

$disQty = -(abs($_POST['disQty']));

Jim

Reply With Quote
  #10  
Old February 14th, 2013, 08:05 AM
jlewis01's Avatar
jlewis01 jlewis01 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Apr 2004
Posts: 234 jlewis01 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Days 16 h 8 m 56 sec
Reputation Power: 10
Quote:
Originally Posted by Jacques1
Yes! Because that actually generates an error, which can be turned off later, redirected to a log file etc.

A die() just dumps its output on the page, not matter if it's you testing the code on your local server or your users visiting your live site. Query errors expose a lot of the internal database code, so they can be used to launch attacks specifically on weak parts of the code.

In conjunction with the injection vulnerabilities (which are still there), I fear your website wouldn't last very long. There are automated tools for this, so it doesn't even have to be a genius "hacker".



I will address the vulnerabilities. 90% of the database is set to INT and this is not a public site.

Reply With Quote
  #11  
Old February 14th, 2013, 08:32 AM
Jacques1's Avatar
Jacques1 Jacques1 is offline
pollyanna
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 2012
Location: Germany
Posts: 2,042 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 3 Weeks 41 m 33 sec
Reputation Power: 812
Quote:
Originally Posted by jlewis01
90% of the database is set to INT


That makes no difference. The point is that your queries can be manipulated by whoever happens to visit the site. If you check testing tools like sqlmap, you'll realize those vulnerabilities can compromise your whole server. So even if you don't give a damn about your data, I'm pretty sure you do care about your server.



Quote:
Originally Posted by jlewis01
and this is not a public site.


I know, there are a thousand justifications for unsecure code (it's a private site, it's just for testing, we'll rewrite everything later and so on).

But, seriously: Aren't those just excuses? Security isn't "only" about protecting yourself against evil hackers, it's also about correct code. Using unescaped variables is technically wrong, because the whole thing will blow up as soon as the input happens to contain characters like quotes, slashes, hyphens etc. So you don't even need an actual attacker, who does this on purpose.

To put it bluntly: security holes are bugs, even if nobody has noticed them yet.

I understand that you might have to deal with a lot of legacy code you cannot possibly rewrite. But at least for new features, it might be a good idea to be conscious of those issues and do it properly.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPHP Development > Turn an number negative

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