Help - Search - Members - Calendar
Full Version: Trouble "fetching" A Variable From A Form
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
kevin_k
Hello All:

I have a script that allows users to register for my website ( kevtek.uuuq.com ) and I'm having trouble with one variable it seems. As a diagnostic tool the script currently simply reports the contents of the fields plus a few other variables that will be passed ultimately to the MySQL database. Also, I didn't want visitors to see an error page so I allowed them to participate in the development of the script as I work on it. This is actually the purpose of my site - developing website content and code. You can go directly to my registration page to get a more clear idea of what I'm talking about here.

I develop my pages and code on my local system using WAMP (Windows Apache MySQL and PHPAdmin) - very handy - then FTP my files to the uuuq server. My code works on the local server but the variable is dropped on the uuuq server for some reason.

Depending on the state of the "Usage Statement" checkbox the variable should contain either "on" if checked, and blank or empty for unchecked. Here is the html statement for my checkbox:

CODE
<td id="reg_fields">
<input type="checkbox" name="reg_agree" />  Check here Please
</td>


Here is the relevant PHP code, I've snipped out things that would just clutter the codebox up. If people think that posting the whole script is required I'll certainly be happy to oblige.

CODE
<?php
// Assign form variables
$username = $_POST['reg_user'];
$password1 = $_POST['reg_pswd1'];
$password2 = $_POST['reg_pswd2'];
$email1 = $_POST['reg_mail1'];
$email2 = $_POST['reg_mail2'];
$dob_month = $_POST['dob_month'];
$dob_day = $_POST['dob_day'];
$dob_year = $_POST['dob_year'];
$agree = $_POST['reg_agree'];

// ...snip...

// Display data
// Other variables are displayed as well - they were omitted
echo "Usage Agreement Raw : " . $agree . "<br />";
echo "Usage Agreement : ";

// Translate value
if ($agree == "on") {
echo "Yes";
} else {
echo "No";
}

echo "<br />";

?>


Again, the script works fine on my local system but drops this variable on the uuuq server. Perhaps I am missing something...

You can look at the site via the links above - this may help clarify what I'm trying to express. Fill out the form (don't use your real passwords of course) and hit the "Register" button to see what is going on. If anyone has an idea what I've done or not done I'd appreciate the assist. Thanks in advance.

Kev
Ed
Have you tried print_r($_POST), what does reg_agree return when you submit with it checked?

I just tried throwing up a simple script, that returns on.
http://online.uuuq.com/form.php

You could just check if it's set to see if it's checked:

CODE
if(isset($_POST['reg_agree']))
    // Agreed
else
    // Not agreed
kevin_k
QUOTE(Bread @ Jun 28 2009, 06:55 PM) *
Have you tried print_r($_POST), what does reg_agree return when you submit with it checked?

I just tried throwing up a simple script, that returns on.
http://online.uuuq.com/form.php

You could just check if it's set to see if it's checked:

CODE
if(isset($_POST['reg_agree']))
    // Agreed
else
    // Not agreed


OK, I'll try those things and get back to you - thanks.
kevin_k
Hi Bread:

Well, here's what happened. I used print_r($_POST) as you suggested to dump the raw array and found the trouble. Somehow an old variable name "privacy" was still in the checkbox name attribute instead of the newer variable name "reg_agree".

Perhaps I didn't update the register.php file on the uuuq server. I did go into the online editor to fix the issue and, surprisingly, it still kept the old variable name when I checked the form/script combination on the remote site - weird. I verified that the register.php file on my local system had the correct variable name and used the online file manager to upload the file to the Zymic server - problem finally solved, its now working as expected.

Thanks for your quick reply and expert help. I appreciate it.
Ed
QUOTE(kevin_k @ Jun 29 2009, 12:23 AM) *
Hi Bread:

Well, here's what happened. I used print_r($_POST) as you suggested to dump the raw array and found the trouble. Somehow an old variable name "privacy" was still in the checkbox name attribute instead of the newer variable name "reg_agree".

Perhaps I didn't update the register.php file on the uuuq server. I did go into the online editor to fix the issue and, surprisingly, it still kept the old variable name when I checked the form/script combination on the remote site - weird. I verified that the register.php file on my local system had the correct variable name and used the online file manager to upload the file to the Zymic server - problem finally solved, its now working as expected.

Thanks for your quick reply and expert help. I appreciate it.


Sounds like some strange behavior, the online editor is at best buggy, it's much better to either use the upload (as you did) or ftp.

Might be a cached copy too, clearing the cache or doing a hard refresh is best after doing an upload, shift click refresh is pretty universal for doing that.

Glad to hear you have it sorted though smile.gif
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.