| | |
Validate Input Fields
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
•
•
Perhaps I've misunderstood the question, and the two previous posters used regular expressions but I would normally test a date with something like the following:
PHP Syntax (Toggle Plain Text)
function is_date($value) { // If the value of the field is empty, immediately return false. if (empty($value)) { return FALSE; } // Attach the exploded values to variables. list($day, $month, $year) = explode("/", $value); // Check those variables in the checkdate function. If it's valid, the function returns true. return checkdate($month, $day, $year); }
return "$year - $month - $day"; if it is a valid date or FALSE if it isn't seeing as you already have the variables set.As for the time, I would probably take the input as a string and use one of the regular expression checks above to see if it consists of 4 numbers, then typecast it to an integer and check
if ($time_num >= 900 && $time_num <= 1700) { echo "time is valid"; } ★ "If your not having fun, your doing something wrong." - Humbug
★ Did I help you out? Did I piss you off? Add to my reputation!
★ The Gabriel Method is a great book for losing weight and keeping healthy - I know Jon Gabriel Personally.
★ Did I help you out? Did I piss you off? Add to my reputation!
★ The Gabriel Method is a great book for losing weight and keeping healthy - I know Jon Gabriel Personally.
Great Stuff!
Your postings have giving me much understanding of most issues.
start_time is a varchar data type, is it possible to perform an addition on this variable?
Supposing $start_time has a value 1100 because I am using 24 hour format can I add a value to it?
ie. $start_time = $start_time + 100;
Your postings have giving me much understanding of most issues.
start_time is a varchar data type, is it possible to perform an addition on this variable?
Supposing $start_time has a value 1100 because I am using 24 hour format can I add a value to it?
ie. $start_time = $start_time + 100;
It is NO SHAME to ask when you want to LEARN, but FOOLISH to behave knowledgeable when YOU DON'T.
Keep PEACE alive!
Keep PEACE alive!
In php, if you try to perform an operation on $start_time (assuming that it is a variable in the script containing a string) it will be used as an integer. It works fine if the string is something like "1234". $start_time will then be converted to an integer variable (because it is on the left of the "=").
If there is a column in a mysql table that is named "start_time" and is a varchar datatype and you do something like
If you are writing a query to submit data to the mysql database and you can do something like With the single quotes ('), the mysql treats whatever is in them as a string no matter what. When you do
This changing types is called "typecasting" if you want to research it more or anything like that.
If there is a column in a mysql table that is named "start_time" and is a varchar datatype and you do something like
$start_time = $row['start_time'] (where $row contains a row of a result from a query) then $start_time will be a string.If you are writing a query to submit data to the mysql database and you can do something like
php Syntax (Toggle Plain Text)
$query = "INSERT INTO table (`start_time`, `finish_time`) VALUES ( " . $start_time . ", " . $finish_time . ")"; //or $query = "INSERT INTO table (`start_time`, `finish_time`) VALUES ( '" . $start_time . "', '" . $finish_time . "')";
$string = "$int"; or $string = "number is " . $int; , $int is used as a string. So when you are creating the query it doesn't matter what type $start_time is. Without the single quotes I think SQL will assume it's whatever type it needs to be. (mysql converts it to the right data type anyway so there's usually no problem). Just be careful doing "... WHERE culumn_name=$string" instead of "... WHERE culumn_name='$string'" because other wise only the first word of $string will be used.This changing types is called "typecasting" if you want to research it more or anything like that.
★ "If your not having fun, your doing something wrong." - Humbug
★ Did I help you out? Did I piss you off? Add to my reputation!
★ The Gabriel Method is a great book for losing weight and keeping healthy - I know Jon Gabriel Personally.
★ Did I help you out? Did I piss you off? Add to my reputation!
★ The Gabriel Method is a great book for losing weight and keeping healthy - I know Jon Gabriel Personally.
![]() |
Similar Threads
- how to validate text file, loading into listbox (Visual Basic 4 / 5 / 6)
- Homework Help (Java)
- Homework Help (Community Introductions)
- Javascript, Form fields validation and submit (JavaScript / DHTML / AJAX)
- "how to": 2 questions: (Java)
- Input Text colour in forms and submit (Graphics and Multimedia)
Other Threads in the PHP Forum
- Previous Thread: need help with two simple php scripts
- Next Thread: php validation before file upload
| Thread Tools | Search this Thread |
.htaccess action ajax apache api array auto beginner binary bounce broken cakephp checkbox class cms code cron curl database date display dynamic echo email error errorlog file files folder form format forms function functions google href htaccess html image include insert integration interactive ip java javascript joomla limit link login loop mail malfunctioning masterthesis menu mlm mod_rewrite multiple mysql nodes oop paypal pdf php popup problem query radio ram random recursion reference regex remote return script search server sessions sms soap source space sql syntax system table tutorial unset update upload url validation validator variable video web websitecontactform xml youtube





