TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-08-2009, 02:53 PM   #1 (permalink)
The Contributor
 
Join Date: Sep 2008
Posts: 39
Thanks: 9
code_junkie is on a distinguished road
Default Search by date range problem

I have a script the searches by date range, work s great. However, being in the new year I noticed if I do a search from 08 to 09 it doesn't return any result but if I search in just 08 or 09 it returns result correctly. Any ideas?
__________________
Trying to learn all I can about PHP. Teach me what you know...
code_junkie is offline  
Reply With Quote
Old 01-08-2009, 03:01 PM   #2 (permalink)
The Addict
 
Enfernikus's Avatar
 
Join Date: Jun 2008
Posts: 335
Thanks: 2
Enfernikus is on a distinguished road
Default

Can you please post the script so we can see the problem?
Enfernikus is offline  
Reply With Quote
Old 01-08-2009, 03:51 PM   #3 (permalink)
The Contributor
 
Join Date: Sep 2008
Posts: 39
Thanks: 9
code_junkie is on a distinguished road
Default

HTML:
Code:
<form action="search_results.php" method="post" name="search_form">
		  <div class="row">
		    <div class="report_title"><p>Start Date:</p></div>
			<div class="report_field"><p><input name="date_start" type="text" id="date_start" maxlength="8" /></p></div>
		  </div>
		<div class="form_padding"></div>
		  <div class="row">
		    <div class="report_title"><p>End Date:</p></div>
			<div class="report_field"><p><input name="date_end" type="text" id="date_end" maxlength="8" /></p></div>
		  </div>
		<div class="form_padding"></div>
		  <div class="row">
		    <div class="report_title"><p>&nbsp;</p></div>
			<div class="report_field"><p><input type="reset" value="Reset" name="reset" />  <input type="submit" name="submit" value="Submit" /></p></div>
		  </div>
		<div class="clear"></div>
		</form>
PHP:
Code:
$MM_username = $_SESSION['MM_Username'];
error_reporting(E_ALL);
ini_set('display_errors', '1');

$maxRows_Recordset1 = 100;
$pageNum_Recordset1 = 0;
if (isset($_GET['pageNum_Recordset1'])) {
  $pageNum_Recordset1 = $_GET['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

mysql_select_db($database_Company, $Company);
$query_Recordset1 = "SELECT * FROM call_in,drivers,company WHERE call_in.company_id = $MM_username AND call_in.company_id = company.company_id AND call_in.driver_id = drivers.driver_id AND call_in.date BETWEEN '" . $_POST['date_start'] . "' AND '" . $_POST['date_end'] . "' ORDER BY call_in.date DESC";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $Company) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($_GET['totalRows_Recordset1'])) {
  $totalRows_Recordset1 = $_GET['totalRows_Recordset1'];
} else {
  $all_Recordset1 = mysql_query($query_Recordset1);
  $totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
__________________
Trying to learn all I can about PHP. Teach me what you know...
code_junkie is offline  
Reply With Quote
Old 01-08-2009, 04:27 PM   #4 (permalink)
The Contributor
 
Join Date: Jan 2009
Posts: 40
Thanks: 10
Scottymeuk is on a distinguished road
Default

I really hope your not using that code live as its so insecure.
Scottymeuk is offline  
Reply With Quote
Old 01-08-2009, 04:32 PM   #5 (permalink)
The Contributor
 
Join Date: Sep 2008
Posts: 39
Thanks: 9
code_junkie is on a distinguished road
Default

No, how would I secure it? I'm not that familiar with php.
__________________
Trying to learn all I can about PHP. Teach me what you know...
code_junkie is offline  
Reply With Quote
Old 01-08-2009, 08:04 PM   #6 (permalink)
The Contributor
 
Join Date: Jan 2009
Posts: 40
Thanks: 10
Scottymeuk is on a distinguished road
Default

You need to secure all of the $_POST and $_GET methods. An example is below (Please note that the mysql function I am using is the minimum you need to do. You should do a lot more and im sure if you search here you will find some tutorials on it. Search for xss protection or something):

PHP Code:
$theGet mysql_real_escape_string($_GET['theGet']); 
Scottymeuk is offline  
Reply With Quote
Old 01-08-2009, 08:41 PM   #7 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Quote:
Search for xss protection or something
You mean SQL Injections, XSS (Cross Site Scripting) is when you allow a malicious user to enter unclean data (usually containing javascript code) to your site, which is then inturn displayed (at some point) to an unsuspecting user allowing the attacker to send sensitive data from that user (like cookies) elsewhere. SQL injection is where you allow a malicous user to 'Inject' his owb SQL commands through an unprotected SQL query (such as the one posted above)

I think these articles may help you understand:
Securing your MySQL Queries with Sprintf
How to Login to Any Account on an Insecure Site
http://www.tizag.com/mysqlTutorial/m...-injection.php

Also I advise that you turn error reporting off in a live server environment, don't make the hackers life easy by giving him feedback on his attempts (which in essence is what happens with errors).

Anyway to the problem. Is your database stripping of the preceding zero?, I say this because you are sending both 09 and 08 in the between statement as string (wrapped in single quotes), thus the db will be comparing:

the string "08" and the integer 8
and so on and so forth.

In other words, what's the column's data type? and what does it currently hold
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
The Following 2 Users Say Thank You to sketchMedia For This Useful Post:
code_junkie (01-09-2009), Scottymeuk (01-08-2009)
Old 01-08-2009, 08:58 PM   #8 (permalink)
The Contributor
 
Join Date: Jan 2009
Posts: 40
Thanks: 10
Scottymeuk is on a distinguished road
Default

Quote:
Originally Posted by sketchMedia View Post
You mean SQL Injections, XSS (Cross Site Scripting) is when you allow a malicious user to enter unclean data (usually containing javascript code) to your site, which is then inturn displayed (at some point) to an unsuspecting user allowing the attacker to send sensitive data from that user (like cookies) elsewhere. SQL injection is where you allow a malicous user to 'Inject' his owb SQL commands through an unprotected SQL query (such as the one posted above)

I think these articles may help you understand:
Securing your MySQL Queries with Sprintf
How to Login to Any Account on an Insecure Site
http://www.tizag.com/mysqlTutorial/m...-injection.php

Also I advise that you turn error reporting off in a live server environment, don't make the hackers life easy by giving him feedback on his attempts (which in essence is what happens with errors).

Anyway to the problem. Is your database stripping of the preceding zero?, I say this because you are sending both 09 and 08 in the between statement as string (wrapped in single quotes), thus the db will be comparing:

the string "08" and the integer 8
and so on and so forth.

In other words, what's the column's data type? and what does it currently hold

Ye, my bad. I was thinking of xss mainly as i was just trying it out on a script. Sorry.
Scottymeuk is offline  
Reply With Quote
Old 01-08-2009, 10:12 PM   #9 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Quote:
Ye, my bad. I was thinking of xss mainly as i was just trying it out on a script. Sorry.
hehe no probs mate, we all make mistakes.
Its hard to keep up with all these acronyms!
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Old 01-09-2009, 12:55 PM   #10 (permalink)
The Contributor
 
Join Date: Sep 2008
Posts: 39
Thanks: 9
code_junkie is on a distinguished road
Default

Quote:
Originally Posted by sketchMedia View Post
You mean SQL Injections, XSS (Cross Site Scripting) is when you allow a malicious user to enter unclean data (usually containing javascript code) to your site, which is then inturn displayed (at some point) to an unsuspecting user allowing the attacker to send sensitive data from that user (like cookies) elsewhere. SQL injection is where you allow a malicous user to 'Inject' his owb SQL commands through an unprotected SQL query (such as the one posted above)

I think these articles may help you understand:
Securing your MySQL Queries with Sprintf
How to Login to Any Account on an Insecure Site
http://www.tizag.com/mysqlTutorial/m...-injection.php

Also I advise that you turn error reporting off in a live server environment, don't make the hackers life easy by giving him feedback on his attempts (which in essence is what happens with errors).

Anyway to the problem. Is your database stripping of the preceding zero?, I say this because you are sending both 09 and 08 in the between statement as string (wrapped in single quotes), thus the db will be comparing:

the string "08" and the integer 8
and so on and so forth.

In other words, what's the column's data type? and what does it currently hold
Thanks for the links, I'll read up on those as soon as I can. As for the db, there is a field for date. I guess I should have used the whole thing in my question. The dates are displayed as 12252008 or 1092009.
__________________
Trying to learn all I can about PHP. Teach me what you know...
code_junkie is offline  
Reply With Quote
Old 01-09-2009, 04:13 PM   #11 (permalink)
The Contributor
 
Join Date: Jan 2009
Posts: 40
Thanks: 10
Scottymeuk is on a distinguished road
Default

use:

PHP Code:
$date date('Y',$dbRow['date']); 
To be able to get the year from the time stamp. Not sure if thats what you need but it should help if you do.

Last edited by Scottymeuk : 01-09-2009 at 04:45 PM.
Scottymeuk is offline  
Reply With Quote
Old 01-09-2009, 04:36 PM   #12 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

What is the columns datatype?
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Huge Session Problem Killswitch General 1 11-17-2008 01:36 AM
help me figure out this date thing sarmenhb Absolute Beginners 5 09-15-2008 04:20 PM
Searching DB Problem StevenF Absolute Beginners 6 02-28-2008 11:32 PM
Need more ideas for date and time class Wildhoney General 2 01-18-2008 01:22 PM
selecting a date range meshi Absolute Beginners 3 11-29-2007 01:30 PM


All times are GMT. The time now is 03:58 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design