hello again,

Having a prob with a form. 😕 Here is the error that I am getting:

Notice: Undefined index: submit in c:\program files\blah blah blah\rpgname.php on line 3

Here is the code:

<h2>Roleplaying Name Generator</h2>
<?php
$submit = $_POST['submit'];
if($submit){
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$mothersmaiden = $_POST['mothersmaiden'];
$citybornin = $_POST['citybornin'];

$firstpart1 = substr($lastname, 0, 3);
$firstpart2 = strtolower(substr($firstname, 0, 2));

$lastpart1 = substr($mothersmaiden, 0, 2);
$lastpart2 = strtolower(substr($citybornin, 0, 3));


$swfirstname = $firstpart1.$firstpart2;
$swlastname = $lastpart1.$lastpart2;
print("Your roleplaying name is:<p>");
print("$swfirstname $swlastname");
} else {
?>
Enter your information below and get your roleplaying name.<p>
<form action="rpgname.php" method="post">
<input type="hidden" name="submit" value="submit">
	<table>
		<tr>
			<td>Your First Name</td>
			<td><input type="text" name="firstname"></td>
		</tr>
		<tr>
			<td>Your Last name</td>
			<td><input type="text" name="lastname"></td>
		</tr>
		<tr>
			<td>Your Mother's Maiden Name</td>
			<td><input type="text" name="mothersmaiden"></td>
		</tr>
		<tr>
			<td>The name of the city in which you were born</td>
			<td><input type="text" name="citybornin"></td>
		</tr>
		<tr>
			<td></td>
			<td><input type="submit" value="Generate Your Name">
	</table>
</form>
<?
}
?>

I think it has something to do with my phpini setting. If this is the case, which one would it be and what should the setting be?

Thanks a mil,
Todd

    Check your incoming variables with [man]isset/man or [man]empty/man before using them.

      Or suppress the notice, using @ $_POST['submit'].

      In any case it's bad form to have apps which generate warnings (even notices) during normal operation.

      Mark

        You need to use the same index name as that given in the "name" attribute in your form. e.g.

        <input type="submit" name="submit" value="Generate Your Name">

        Then you can use:

        $submit = $_POST['submit']

          2 years later

          I'm having somewhat the same problem, but my naming is similar. I get the message:

          Notice: Undefined index: submit in /home/arioch/public_html/setup.php on line 85

          The relevant chunk:

          <?php
          ini_set('display_errors', true);
          //error_reporting(E_ALL ^ E_NOTICE);
          function form(){
          ?>
          <form id="dblink_params" name="dblink_params" method="post" action="<?php echo $PHP_SELF;?>">
             <fieldset class="formfield">
              <legend class="hlook1">1). YOUR DATABASE CONNECTION PARAMETERS:</legend>
                <label>Database name:</label><input type="text" size="20" name="dbname" /><br />
                <label>Database hostname:</label><input type="text" size="20" name="dbhost" /><br />
                <label>Database username:</label><input type="text" size="20" name="dbusername" /><br />
                <label>Database password:</label><input type="password" size="20" name="dbpassword" />
            </fieldset>
          <input type="submit" value="submit" name="submit">
          </form>
          <?php
          }
          //registering the condition of the submit button. If set(clicked) proceed with script. if not(false) die and display form.
          $button = ($_POST['submit']);
          if (!isset($button)) die (form());

          UPDATE: Now, I'm also getting this message: The requested URL not found? I'm using PHP_SELF...

          Object not found!

          The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

          If you think this is a server error, please contact the webmaster.
          Error 404

          What is going on? I'm running my own machine by the way, no webhotel.

          1. UPDATE: The "ini_set('display_errors', true);" is responsible for all of it.

            Probably should have used 'On' instead of TRUE.

            By the way, you fix the undefined index error by doing something like:

            if(isset($_POST['submit']))

            instead of

            $button = ($_POST['submit']); 
            if (!isset($button))

            See the difference? In your code, you are still trying to use the $_POST['submit'] array item whether it exists or not.

              Ok, I get it, thanks.

              I changed init_error to "ON" instead of "true", but I get the same message regardless. Is this anything I need to,, worry about?

                spookztar wrote:

                Is this anything I need to,, [sic] worry about?

                Well, for production purposes not really - you don't want to display errors to the outside world.

                For debugging purposes, though, it might be handy to have errors turned on, yeah. On my production server, when I want to see errors within a script, I put this at the top:

                <?php
                ini_set('display_errors', 'On');
                error_reporting(E_ALL);

                  Just to be clear, the message I was talking about was the OBJECT NOT FOUND!..

                    Check the HTML of the page to see what value is apppearing at the spot where you're using $PHP_SELF. If it's blank then it's pretty sure to mean that you should be using $_SERVER['PHP_SELF'] (actually you should be using that anyway).

                      That was it, and what you said did it. Thanks.

                        Write a Reply...