homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

Undefined variable: maidenname in.

 4:57 pm on Mar 30, 2012 (gmt 0)

My registration.php form has questions that have to be answered and three that are optional. The three that are optional give me this error in the box when tested in browser.

<br /><b>Notice</b>: Undefined variable: maidenname in <b>/home/*******/********/root/registration.php</b> on line <b>304</b><br />

How do I clear it to make an empty box?

Thanks, Scott



 6:19 pm on Mar 30, 2012 (gmt 0)

Your question does not seem to pertain to the error message you are getting from what I can tell.

1) The reason you are getting this error message is because these specific variables were not part of the POSTed data sent to the action form. For these (and really all of them), you should be checking for existance before processing anything, e.g.:

if(isset($_POST['input_name])) {
// do something
} else {
// handle undefined case

2) >How do I clear it to make an empty box?
Can you elaborate here? Not sure exactly what you mean.


 7:08 pm on Mar 30, 2012 (gmt 0)

Sorry, the error message is in the formField were the maidenname would go.


 7:14 pm on Mar 30, 2012 (gmt 0)

Oh so you are doing something like this, then?

<input type="text" name="maidenname" value="<?php echo $_POST['maidenname']; ?>"/>

If that is the case, you need to first check to see if it exists -- if it does you put in the value of the variable, if it doesn't you put in some default value. Here is a simplified version:

$maidenname = $_POST['maidenname'];
$maidenname = "";
echo '<input type="text" name="maidenname" value="' . $maidenname .'"/>';

Let me know if this helps.


 7:21 pm on Mar 30, 2012 (gmt 0)

Or use a little function like this for all your fields:

# get parameters passed by POST or GET
# protected against throwing warnings
function get_post($var) {
return isset($_POST[$var]) ? $_POST[$var] : false;

Then you can call the function for all form fields, a lot less code to weed through, and anything not filled in won't generate errors:

$maidenname = get_post('maidenname');

If you don't want to be able to check if the value is actually not set, or false, and prefer a blank, change the function to be:

function get_post($var) {
return isset($_POST[$var]) ? $_POST[$var] : "";


 7:33 pm on Mar 30, 2012 (gmt 0)

THANK YOU! I'll try above comments. This is what I'm working with in the table...

<td width="136" bgcolor="#FFFFFF"><div align="right">Maiden Name:</div></td>
<td width="360" bgcolor="#FFFFFF"><div align="left">
<input name="maidenname" type="text" class="formFields" id="maidenname" value="<?php print "$maidenname"; ?>" size="32" maxlength="20" />
<span id="nameresponse"><span class="textSize_9px"><span class="greyColor">Alphanumeric Characters Only</span></span></span></div></td>


 7:39 pm on Mar 30, 2012 (gmt 0)

Thanks! FIXED!

Was missing $maidenname = "";


 7:43 pm on Mar 30, 2012 (gmt 0)

With a little bit of CSS you could do away with the div and span code bloat in that example.


 8:14 pm on Mar 30, 2012 (gmt 0)

I mean if you want to get fancy, bill, this is how I would do it ;)

function get_post($var, $default = "") {
return isset($_POST[$var]) ? $_POST[$var] : $default;

That way you have one function for every possible need:

get_post('maidenname', 'Maiden Name');

But I showed it as I did above for its simplicity.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved