I need some help with this one guys. I made a small script that inputs only numbers with 4 digits. Now the trick is that I need to input only numbers higher than 0 (ranged from 1 to 9999). Easy enough, I said, if I only make this rule: $val<=0. But the problem here is that if I input the number 01 or 001 or 0001, it is submitted to the query. I could do this: $val<=1, but then I would need the number 1 to be submitted so this didn't get me very far. Is there a way around this!? Thanks.
seularts 0 Light Poster
Recommended Answers
Jump to Postyou could do an intval() on the input?
check this:
<?php $int = '0001'; echo intval($int); ?>
Jump to PostRe-reading the question, you need input validation.
$x = intval($_POST['field']); $options = array( 'options' => array('min_range' => 1,'max_range' => 9999) ); if (filter_var($x, FILTER_VALIDATE_INT, $options) !== FALSE) { echo "$x is valid between 1 and 9999"; //do sql query }else{ echo "$x is not a valid integer"; …
All 5 Replies

diafol
almostbob 866 Retired: passive income ROCKS
seularts 0 Light Poster
seularts 0 Light Poster

diafol
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.