By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,664 Members | 1,656 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,664 IT Pros & Developers. It's quick & easy.

Passing a _POST key that contains a "."

P: 2
I am passing a _POST key that contains a period and php is replacing it with an underscore. I need to keep the key as say "Test.1". Any ideas?
Oct 28 '08 #1
Share this Question
Share on Google+
4 Replies


Markus
Expert 5K+
P: 6,050
I am passing a _POST key that contains a period and php is replacing it with an underscore. I need to keep the key as say "Test.1". Any ideas?
Hm, PHP shouldn't be doing that.

Show the relevant code you use.

Edit, do you mean the array key is being changed?
Oct 28 '08 #2

P: 2
Expand|Select|Wrap|Line Numbers
  1. //php stuff
  2.  
  3. if($submit) {
  4.         $sql = "SELECT * FROM Release ORDER BY Release";
  5.         $result = mysql_query($sql, $db);
  6.         if($result) {
  7.             echo '<pre>';
  8.             print_r($_POST);
  9.             echo '</pre>';
  10.  
  11.             while($myrow = mysql_fetch_array($result)) {
  12.                 $name = $myrow["Release"] . "_search_string";
  13.                 $dateCode_name = $myrow["Release"] . "_valid_dateCodes";
  14.  
  15.                 $myvar = $myrow["Release"];
  16.  
  17.                 $sql = "REPLACE INTO Release (Release, Supported, search_string,valid_dateCodes) VALUES ('$myvar', '$_POST[$myvar]', '$_POST[$name]', '$_POST[$dateCode_name]')";
  18. }
  19.  
  20. //and relevant html code
  21.  
  22. <FORM ACTION="release.php3?ma=patchguard&sa=editRelease" method="POST">
  23. <TABLE>
  24. <TR><TH>Release</TH><TH>Supported?</TH></TR>
  25. <TR><TD COLSPAN="2"><HR NOSHADE></TD></TR>
  26. <?
  27.     $sql = "SELECT * FROM Release ORDER BY Release";
  28.     $result = mysql_query($sql, $db);
  29.     if($result) {
  30.         while($myrow = mysql_fetch_array($result)) {
  31.  
  32.             $myvar = $myrow["Release"];
  33.  
  34.             $s_value = $myrow["search_string"];
  35.  
  36.             $name = $myvar . "_search_string";
  37.  
  38.             $search_text = "&nbsp;<input type='text' name='$name' size='8' value='$s_value'>";
  39.  
  40.             $s_value = $myrow["valid_dateCodes"];
  41.  
  42.             $dateCode_name = $myvar . "_valid_dateCodes";
  43.  
  44.             $valid_dateCodes = "&nbsp;<input type='text' name='$dateCode_name' size='25' value='$s_value'>";
  45.  
  46.             $myrelease = $myrow["Supported"];
  47.  
  48.             $output = "<TR><TD>" . $myvar . "</TD><TD>No longer supported<INPUT TYPE='radio' NAME='" . $myvar . "' VALUE='noLongerSupported'";
  49.  
  50.             if($myrow["Supported"] == "noLongerSupported") {
  51.                     $outputplus = " CHECKED> Supported<INPUT TYPE='radio' NAME='" . $myvar . "' VALUE='supported'> Future<INPUT TYPE='radio' NAME='" . $myvar . "' VALUE='future'>$search_text $valid_dateCodes</TD></TR>";
  52.                     echo($output . $outputplus);
  53.             }
  54.             else if($myrow["Supported"] == "supported") {
  55.                     $outputplus = "> Supported<INPUT TYPE='radio' NAME='" . $myvar . "' VALUE='supported' CHECKED> Future<INPUT TYPE='radio' NAME='" . $myvar . "' VALUE='future'>$search_text $valid_dateCodes</TD></TR>";
  56.                     echo($output . $outputplus);
  57.             }
  58.             else if($myrow["Supported"] == "future") {
  59.                     $outputplus = "> Supported<INPUT TYPE='radio' NAME='" . $myvar . "' VALUE='supported'> Future<INPUT TYPE='radio' NAME='" . $myvar . "' VALUE='future' CHECKED>$search_text $valid_dateCodes</TD></TR>";
  60.                    echo($output . $outputplus);
  61.             }
  62.             else {
  63.                     echo ("Error outputing $myvar information");
  64.                  }
  65.            }
  66.     }
  67. ?>
  68. <TR><TD COLSPAN="2"><HR NOSHADE></TD></TR>
  69. <TR><TD><INPUT TYPE="text"  NAME="Release"></TD><TD>No longer supported<INPUT TYPE='radio'  NAME='Supported' VALUE='noLongerSupported'> Supported<INPUT TYPE='radio'  NAME='Supported' VALUE='supported' checked> Future<INPUT TYPE='radio'  NAME='Supported' VALUE='future'></T</TD></TR>
  70. <TR><TD COLSPAN="2"><CENTER><INPUT TYPE="submit" NAME="submit" VALUE="Submit"></CENTER></TD></TR>
  71. </TABLE>
  72. </FORM>
When I enter a new "Release" with a "." in it, it works fine at first, but when I make changes to any release it replaces the "." with a "_".

ie. Test.1 becomes Test_1 as shown when I print out the _POST vars, so then when it tries to replace each entry in the DB it cannot find Test_1_search_string and the REPLACE is aborted.

Here is the _POST info for the "Release" that was named "Test.1"

[Test_1] => supported
[Test_1_search_string] =>
[Test_1_valid_dateCodes] =>


Did that make sense????
Oct 28 '08 #3

Markus
Expert 5K+
P: 6,050
I'm not sure but it seems PHP doesn't allow periods in array keys and changes them itself? I don't really now. You could str_replace(".", "_", $var) when you need to use the POST keys.
Oct 28 '08 #4

Atli
Expert 5K+
P: 5,058
Hi.

PHP does not allow periods (dots) in variable names. That includes array elements.

So, if you try to pass a name into PHP that includes a period, in order to be able to import it into your PHP scripts, PHP automatically replaces it with an underscore.

See Variables From External Sources
Oct 29 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.