Jump to content

Problem with comparing data in form


InGale
 Share

Recommended Posts

Hi!I have a form, in which I edit some data, which is retrieved from MySQL, then this data is sent to another file, submit_mag.php, in which I compare some of the data and update MySQL record. So, in the form I have 2 hidden fields: ""issue_current_month" and "issue_current_year". Also, I have 2 select menus: "issue_month" and "issue_year". And here's the part where I retrieve this data in submit_mag.php and compare the data:

$mag_id = (int) $_REQUEST['mag_id'];$issue_num = $_REQUEST['issue_num'];$issue_current_month = $_REQUEST['issue_current_month'];$issue_new_month = $_REQUEST['issue_month'];$issue_current_year = $_REQUEST['issue_current_year'];$issue_new_year = $_REQUEST['issue_year'];$issue_theme = $_REQUEST['issue_theme'];$issue_desc = $_REQUEST['issue_desc'];echo "current month: ", $issue_current_month, "</br>";echo "new month: ", $issue_new_month, "</br>";echo "current year: ", $issue_current_year, "</br>";echo "new year: ", $issue_new_year, "</br></br>";//Compare monthif ($issue_new_month == 0 || $issue_new_month == $issue_current_month){	$issue_month = $issue_current_month;}else{	$issue_month = $issue_new_month;}echo "issue month: ", $issue_month, "</br>";//Compare yearif ($issue_new_year == 0 || $issue_new_year == $issue_current_year){	$issue_year = $issue_current_year;}else{	$issue_year = $issue_new_year;}echo "issue year: ", $issue_year, "</br></br>";

In the first block of echoes I only want to display which data is retrieved from the form (it's only for me, I'll remove this part once everything works correctly). And here's the result I'm having:current month: Augustnew month: Sеptembercurrent year: 2011new year: 2012So far - so good.Now, when I'm trying to make the comparison and to set variables $issue_month and $issue_year, I'm having a problem with $issue_month. The echoes of these variables show me this:issue month: Augustissue year: 2012So the year comparison and setting the $issue_year works just fine. But for some reason I'm having trouble with the month, after the comparison I keep getting current month. Any ideas why is that? Thank you!

Link to comment
Share on other sites

When you compare a string with 0 (or any other number), PHP will convert the string to a number and compare it with the other number. So it converts "September" to a number, and that converts to the number 0. So the condition $issue_new_month == 0 is true. Does your form really submit a 0 when they haven't picked a month, or else it submits a string month name?

Link to comment
Share on other sites

When you compare a string with 0 (or any other number), PHP will convert the string to a number and compare it with the other number. So it converts "September" to a number, and that converts to the number 0. So the condition $issue_new_month == 0 is true. Does your form really submit a 0 when they haven't picked a month, or else it submits a string month name?
Yes, if I don't pick a month it submits a 0. This is the code of this part of the form:
<input name="issue_current_month" type="hidden" id="issue_current_month" value="<?php echo $issue_month ?>" /><?php echo "Current month: ", $issue_month; ?> <select name="issue_new_month" id="issue_new_month">			<option value="0" selected="selected" >Change month</option>			<option value="January">January</option>			<option value="February">February</option>			<option value="March">March</option>			<option value="April">April</option>			<option value="Мay">Мay</option>			<option value="June">June</option>			<option value="July">July</option>			<option value="August">August</option>			<option value="September">September</option>			<option value="October">October</option>			<option value="November">November</option>			<option value="December">December</option>		  </select>

Link to comment
Share on other sites

OK, I tried it and it still didn't work... This is the code:

if ($issue_new_month == "0" || $issue_new_month == $issue_current_month){	$issue_month = $issue_current_month;}else{	$issue_month = $issue_new_month;}

Another thing came to mind: the months names and their values are written in Russian. Is it possible that maybe I'm having some sort of encoding issue, even though I have everything set to utf-8, including MySQL db? How can I check it?I have another question, not related: how do I configure a completely new .htaccess file? I have no idea how to do it... I need to set some permissions to allow uploading of files larger than 2 Mb and longer script execution time. I have it set in my php.ini file on my PC, but the server where I'm uploading the site is an Apache and requires .htaccess...

Link to comment
Share on other sites

Print out everything you're checking so you can verify the values. Write it to a file if you need to.Check here:http://www.php.net/manual/en/configuration.changes.php
Well, I guess the problem was in encoding - I changed the values to English and everything worked OK. Then I just had to make some if statements and replace the English name with Russian.Now regarding this .htaccess... I tried to read it, but I still can't figure it out... I tried to simply put this in the file:upload_max_filesize = 50M post_max_size = 50M max_input_time = 600 max_execution_time = 600and now I'm getting this server error: Internal Server ErrorThe server encountered an internal error or misconfiguration and was unable to complete your request.So what am I doing wrong? How can I fix it?
Link to comment
Share on other sites

Looks like somehow I made it work... This is the current code:php_value upload_max_filesize 60M php_value post_max_size 80M php_value max_input_time 800 php_value max_execution_time 800justsomeguy, thank you very much for all your help!!! I really appreciate it! Thank you!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...