PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
tags where approriate when posting code. Read: [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
hi, Im new to php
I'm getting a warrning undefined Offset that occurs twice. The full error is "Undefined offset: 2 The textbox input is dd/mm/yyyy. And returns the yyyy/mm/dd. It queries the db fine and returns the proper results. The warning only comes up when you load the initial page.
Code As Follows:
since you didn't post any more code, I can only assume it's a problem with the $date value not exploding into 3 values for the list call to work. You may want to verify that they are getting broken apart correctly..
function ValidateSearch($date){
global $msg;
if(!ereg('^([0-9]{2})/([0-9]{2})/([0-9]{4})$',$date,$parts)){
$msg .= (!empty($msg)) ? '<BR>': '';
$msg .= "Invalid birthdate format entry enter dd/mm/yyyy";
}
if(!checkdate ($parts[2],$parts[1],$parts[3])){
$msg .= (!empty($msg)) ? '<BR>': '';
$msg .= "The date of birth is invalid. Check that month is between 1-12
and day is valid for that month.";}
list($day,$month,$year) = explode("/",$date);
$timestamp = mktime(0, 0, 0, $month,$day,$year);
$datevariable = date("Y-m-d",$timestamp);
$query = "Select * From calander WHERE task_date = '$datevariable' ";
echo " ";
echo "querry is ",$query;
$result = mysql_query($query);
if(!$result){
echo "Error in search for results:".mysql_error();
//exit();
}
I gather it explodes O.K since it queries the db and returns the proper results
What's the reason for exploding the date, when you've already extracted them to $parts? You don't need the mktime() and date() calls either by that point. You can just place the $parts pieces into the proper order.
line. The reason I exploded it is because the $parts have to be changed fron dd/mm/yyyy(which is the input from a text box) to yyyy/mm/dd. When I dont explode the parts it wont give me the yyyy/mm/dd. It will see it as mm/dd/yyyy
The error suggests that $date is not in dd/mm/yyyy format, but more like dd/mmyyyy format.
Right beofre the explode line can you do an echo $date; and post the output?
if I type in 22/12/2004 it will echo 22/12/2004. The problem occurs before I type anything in(when the page loads). After I type in the date and submit, it works and there is no warning. The whole problem is when I enter that particular page on loading.
Ah, sounds like you are validating the date before it's even submitted, so maybe ValidateSearch() is being called too previous.
You'll only want to call ValidateSearch() on a form post, so something like,