flyersun Posted January 20, 2007 Share Posted January 20, 2007 I'm a bit of a newbie I'm doing a web design degree at the moment as as part of it we have to do php anyways I've created a script which inputs info into a mysql database. Some of the info which needs to be inputted is numeric but the script seems to be eating some of the numbers before they even get to the database. It seems to like 1 and 0's the most. Any ideas how I can fix it's it's really a pain?Amy Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted January 20, 2007 Share Posted January 20, 2007 Please post your script and some examples. Your explanation is about as clear as mud.Ken Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 20, 2007 Share Posted January 20, 2007 *chomp chomp*my favorites are the 5s. They taste like chicken. Quote Link to comment Share on other sites More sharing options...
Caesar Posted January 20, 2007 Share Posted January 20, 2007 [quote author=jesirose link=topic=123205.msg508930#msg508930 date=1169254034]*chomp chomp*my favorites are the 5s. They taste like chicken.[/quote]9's aren't bad either if you have a nice merlot to compliment them with. Quote Link to comment Share on other sites More sharing options...
flyersun Posted January 21, 2007 Author Share Posted January 21, 2007 <form method="post" action="customer_details_validate.php"> <?php echo"<select name='days'>"; $days = 1; while ($days <= 31) { echo"<option value='$days'>" . $days ."</option>"; $days++; } echo"<select name='month'>"; $month = 1; while ($month <= 12) { echo"<option value='$month'>" . $month ."</option>"; $month++; } echo "</select>"; echo"<select name='year'>"; $year = 2007; while ($year >= 1907) { echo"<option value='$year'>" . $year ."</option>"; $year--; } echo "</select>"; ?> <input type="submit" value="Submit"> This is my script to collect someone's date of birth! it sends the information to another script which is then suposted to add the information to a database. However when the DOB reaches the next script some of the numbers have been chopped off. Is that more clear?I could post the whole script but it is rather large.Any help you have give will be greatly appreciated. Quote Link to comment Share on other sites More sharing options...
Philip Posted January 21, 2007 Share Posted January 21, 2007 What does the form processing side look like?I didn't see anything wrong with this side of the form. :) Quote Link to comment Share on other sites More sharing options...
flyersun Posted January 21, 2007 Author Share Posted January 21, 2007 I haven't finished the script yet becuse I noticed the problem before it was finished but this is the script I'm using to text.//Validate DOBecho $formVars["year"] . $formVars["month"] . $formVars["days"]; [b]<----- this echo statment only gives me 3 or 4 numbers when it should give me 8.[/b] if ((empty($formVars["year"])) || (empty($formVars["month"])) || (empty($formVars["days"]))) { //Users DOB cannot be a null string (empty) $errorString .= "\n<br>You must supply a Date of Birth.";}else{ $dob = $formVars["year"] . "--" . $formVars["month"] . "--" . $formVars["days"];} Quote Link to comment Share on other sites More sharing options...
Philip Posted January 21, 2007 Share Posted January 21, 2007 try putting this right below //Validate DOB[code]<?php //don't put the opening and closing php tags, they are there to highlight the code in this boxecho $_POST['month'] . "<br />";echo $_POST['days'] . "<br />";echo $_POST['year'];?>[/code]and see what you get Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 21, 2007 Share Posted January 21, 2007 do print_r($_POST) to make sure all of your post vars are named the way you think they should be.PS: Instead of while loops, for loops would be more appropriate here.for($i=1; $i<=31; $i++){ echo '<option value="'.$i.'">'.$i.'</option>'; } Quote Link to comment Share on other sites More sharing options...
Nelak Posted January 21, 2007 Share Posted January 21, 2007 If u have any leading zero's and its a int field it will chop them off. Quote Link to comment Share on other sites More sharing options...
flyersun Posted January 22, 2007 Author Share Posted January 22, 2007 Ok I checked using the print_r($_POST); line and the information is getting to the page but when I try and echo it or put it in another verit seems to lose charactors.. I'm suing all strings not number fields. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 22, 2007 Share Posted January 22, 2007 What did the strings ever do to you?Post here what the $_POST array contained from the print_r() Quote Link to comment Share on other sites More sharing options...
flyersun Posted January 22, 2007 Author Share Posted January 22, 2007 Array ( [surname] => [firstname] => [address] => [town] => [county] => [postcode] => [days] => 1 [month] => 1 [year] => 2007 [email] => [tel] => [username] => [password] => [password2] => )I've only filled in the problem fields. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 22, 2007 Share Posted January 22, 2007 So you're saying if you do print $_POST['days'].'-'.$_POST['month'].' '.$_POST['year'];RIGHT under that, it doesn't show all the numbers? Quote Link to comment Share on other sites More sharing options...
flyersun Posted January 22, 2007 Author Share Posted January 22, 2007 Well I'm using echo not print but yep pretty much I will show you want I get: Array ( [surname] => [firstname] => [address] => [town] => [county] => [postcode] => [days] => 1 [month] => 1 [year] => 1998 [email] => [tel] => [username] => [password] => [password2] => ) 998 <-- this is all I get... hmm$formVars[$varname] = trim($value, 100); <--- I do have this line in the script but I don't think that could be it ? Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted January 22, 2007 Share Posted January 22, 2007 trim($value, 100); ... you're telling php "strip all 1's and 0's trytrim($value); :P[url=http://www.php.net/trim]more info on trim[/url] Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 22, 2007 Share Posted January 22, 2007 Why do you keep using $formVars? Where is that coming from? Quote Link to comment Share on other sites More sharing options...
flyersun Posted January 22, 2007 Author Share Posted January 22, 2007 mleh I thought I was telling it to cut of anything ove 100 charactors :S thanks for the help! Quote Link to comment Share on other sites More sharing options...
flyersun Posted January 22, 2007 Author Share Posted January 22, 2007 *shurgs* my uni tutor I've been told it's very old but I've not got around to changing it yet. Quote Link to comment Share on other sites More sharing options...
mainewoods Posted January 22, 2007 Share Posted January 22, 2007 you're not losing the zeroes, you never had them to start with:[code]while ($days <= 31) { echo"<option value='$days'>" . $days ."</option>"; $days++;}[/code]--when the $days variable has the value '5', no zero will be printed. The code produced will read:[code]<option value='5'>5</option>[/code]--if you want the date to print with leading zeroes when necessary do this:[code]// converts single digit number to 2 digit string with leading zeros// single quotes around zero '0' forces conversion to string.if ($formVars["month"] < 10) $formVars["month"] = '0' . $formVars["month"];if ($formVars["days"] < 10) $formVars["days"] = '0' . $formVars["days"];//will now always print 2 digits for month and yearecho $formVars["year"] . $formVars["month"] . $formVars["days"]; [/code] Quote Link to comment Share on other sites More sharing options...
flyersun Posted January 22, 2007 Author Share Posted January 22, 2007 Thanks for your input I think I've sorted it now. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.