473,397 Members | 1,969 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,397 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 1878
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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.