473,238 Members | 1,757 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,238 software developers and data experts.

checkdate and int-conversion

Hi,

I have a form that contains amongst others a text-field where users
should enter their year of birth.

<input type="text" name="year_of_birth">

Within the php script that parses the info, I try to check if a valid
birth-date was given, using the checkdate function. This function
expects integers as parameters, so I tought converting the text to an
integer value would work.

checkdate (1, 1, (int)$_POST["year_of_birth"])

However, this doesn't work, and I cannot seem to find out why... Any clues?

cheers,
E.T.
Jul 17 '05 #1
4 1874
Erik T. wrote:
Within the php script that parses the info, I try to check if a valid
birth-date was given, using the checkdate function. This function
expects integers as parameters, so I tought converting the text to an
integer value would work.

checkdate (1, 1, (int)$_POST["year_of_birth"])

No explicit casting required, PHP will take care of this automatically.
However, this doesn't work, and I cannot seem to find out why... Any
clues?


It doesn't work as it always returns 0/1 or throws an error?

More info required, including your OS.
JW

Jul 17 '05 #2
Janwillem Borleffs wrote:
Erik T. wrote:
Within the php script that parses the info, I try to check if a valid
birth-date was given, using the checkdate function. This function
expects integers as parameters, so I tought converting the text to an
integer value would work.

checkdate (1, 1, (int)$_POST["year_of_birth"])
No explicit casting required, PHP will take care of this automatically.


Without the casting, I get :

Warning: checkdate() expects parameter 3 to be long, string given in
ledenform.php on line 49

Line 49 looks like this:

if ( checkdate ( $_POST["geboortemaand"] , $_POST["geboortedag"],
$_POST["geboortejaar"] ) )

With the typecast, I don't get an error, but checkdate always results as
FALSE.

However, this doesn't work, and I cannot seem to find out why... Any
clues?

It doesn't work as it always returns 0/1 or throws an error?

More info required, including your OS.


I'm hosting this at my provider. php_info result:
http://www.akindovzw.be/info.php
Jul 17 '05 #3
Erik T. wrote:
Without the casting, I get :

Warning: checkdate() expects parameter 3 to be long, string given in
ledenform.php on line 49

This means that $_POST["geboortejaar"] does not start with a digit, but
probably with a white space character.
With the typecast, I don't get an error, but checkdate always results
as FALSE.


When your try to cast a string to an integer and the string doesn't start
with a digit, the result will be 0, which is why checkdate() always returns
false.

Try to apply trim() to $_POST["geboortejaar"] before using it and have a
close look at its value when the problem persists.
JW

Jul 17 '05 #4
Erik T. wrote:
<snip>
checkdate (1, 1, (int)$_POST["year_of_birth"])

However, this doesn't work, and I cannot seem to find out why... Any

clues?

You may want to understand the casting basics in PHP:
1. http://in2.php.net/set_type#50255
2. http://in2.php.net/manual/en/languag...e-juggling.php

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

Jul 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: J. Campbell | last post by:
I'm a novice with c/c++ and have been reading Eckel's book. I'd like some feedback on using this method. What I need to do is treat a string as numeric data. I know how to write functions to...
2
by: CoolPint | last post by:
Can anyone clearly explain the difference between constant reference to pointers and reference to constant pointers? What is const int * & ? Is it a constant reference to a pointer to an...
7
by: Ben | last post by:
Hi all, I'm not yet good at thinking the right way in c++ so although I could solve this problem, I'm not sure if they way I'm thinking of is the best way to do it. I need a data type or class...
1
by: akickdoe22 | last post by:
Please help me finish this program. i have completed the addition and the subtraction parts, but i am stuck on the multiplication and division. any suggestions, hints, code, anyhting. it's not a...
9
by: GRoll21 | last post by:
I have a program here that asks the number of students surveyed. then it will ask how many movies each student has watched. After thats been collected it does functions to find the average, median,...
5
by: Kemal Ozan | last post by:
Hi, I am studying K&R book. On the multidimensional Arrays chapter they say "int (*daytab) is a pointer to an array of 13 integers. The parenthesis are necessary since brackets have higher...
4
by: chrisstankevitz | last post by:
This code does not compile on gcc 3.4.4. Should it? Thanks for your help, Chris //================ #include <set> int main()
14
by: yang__lee | last post by:
Hi, You all know typedef typedef struct g { int a; int b; } google;
16
by: Julia | last post by:
Hi, there, In C programming, for pointer, I saw two programming styles: one is connecting '*' with variable, like, 'int *i'; the other is connecting '*' with data type, like, 'int* i' I...
8
by: beagle197 | last post by:
Folks, Attempting to q-sort an array of int pairs, e.g. {{0,1}, {0, 0}, ...} allocated using malloc/calloc, but the arguments I'm passing to qsort are producing the incorrect results (see...
3
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 3 Jan 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). For other local times, please check World Time Buddy In...
0
by: jianzs | last post by:
Introduction Cloud-native applications are conventionally identified as those designed and nurtured on cloud infrastructure. Such applications, rooted in cloud technologies, skillfully benefit from...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.