Jump to content

form does not submit


2cool

Recommended Posts

I'm working on this code but it keeps pulling out the errors:

 

Error!

The following error(s) occurred:

- You forgot to enter the Username.

- You forgot to enter the password.

- You forgot to enter the DOB.

 

Please try again.

 

 

These are errors that have been placed within the code.

 

I have copied this code over from another page and it worked fine for that, but this one does not happen to pick up the fields i enter into the form, let alone submitting the information into the database.

 

<?php 
require_once("DBConnect.php");//database connection 
session_start();

// Check if the form has been submitted.
if (isset($_POST['submitted'])) {

$errors = array(); // Initialize error array.

// Check for a username.
if (empty($_POST['PatientID'])) {
	$errors[] = 'You forgot to enter the Username.';
} else {
	$myusername = trim($_POST['PatientID']);
}

// Check for a password.
if (empty($_POST['Password'])) {
	$errors[] = 'You forgot to enter the password.';
} else {
	$mypassword = trim($_POST['Password']);
}

// Check for a DOB.
if (empty($_POST['DOB'])) {
	$errors[] = 'You forgot to enter the DOB.';
} else {
	$myDOB = trim($_POST['DOB']);
}



if (empty($errors)) { // If everything's okay.

	// Register the member in the database.

	// Make the query.
	$query = "INSERT INTO main (PatientID, Password, DOB) VALUES ('$myusername', '$mypassword', '$myDOB')";		
	$result = @mysql_query ($query); // Run the query.
	if ($result) { // If it ran OK.

		// Print a message.
		echo '<h1 id="mainhead">Thank you!</h1>
	<p>You are now registered!</p><p><br /></p>';	

		// quit the script (to not show the form).

		exit();

	} else { // If it did not run OK.
		echo '<h1 id="mainhead">System Error</h1>
		<p class="error">You could not be registered due to a system error. We apologize for any inconvenience.</p>'; 
		echo '<p>' . mysql_error() . '<br /><br />Query: ' . $query . '</p>'; // Debugging message.

		exit();
	}

	mysql_close(); // Close the database connection.

} else { // Report the errors.

	echo '<h1 id="mainhead">Error!</h1>
	<p class="error">The following error(s) occurred:<br />';
	foreach ($errors as $msg) { // Print each error.
		echo " - $msg<br />\n";
	}
	echo '</p><p>Please try again.</p><p><br /></p>';

} // End of if (empty($errors)) IF.

} // End of the main Submit conditional.
?>

 

Can anyone help and tell me where I'm going wrong or what I'm missing?

Link to comment
Share on other sites


<h2>Register</h2>
<form action="testing2.php" method="post">
<p>Username: <input type="text" name="member_no" size="15" maxlength="15" value="<?php //if (isset($_POST['PatientID'])) echo $_POST['PatientID']; ?>" /></p>
<p>Password: <input type="text" name="race_no" size="15" maxlength="30" value="<?php //if (isset($_POST['Password'])) echo $_POST['Password']; ?>" /></p>
<p>DOB: <input type="text" name="time" size="20" maxlength="40" value="<?php if (isset($_POST['DOB'])) echo $_POST['DOB']; ?>"  /> </p>
<p><input type="submit" name="submit" value="insertingRecord" /></p>
<input type="hidden" name="submitted" value="TRUE" />
</form>

Link to comment
Share on other sites

Looks like you are not using the same input field names in your script, or at least to me. You

have $_POST['PatientID'] but no input field with the name in your form, it looks like you have

member_no for your patientID. You should make sure your field names are the same one being

called in your script...

 

 

<form action="testing2.php" method="post">
   <p>Username: <input type="text" name="PatientID" size="15" maxlength="15" value="<?php //if (isset($_POST['PatientID'])) echo $_POST['PatientID']; ?>" /></p>
   <p>Password: <input name="Password" type="text" id="Password" value="<?php //if (isset($_POST['Password'])) echo $_POST['Password']; ?>" size="15" maxlength="30" />
   </p>
   <p>DOB: <input name="DOB" type="text" id="DOB" value="<?php if (isset($_POST['DOB'])) echo $_POST['DOB']; ?>" size="20" maxlength="40"  /> 
   </p>
   <p><input type="submit" name="submit" value="insertingRecord" /></p>
   <input type="hidden" name="submitted" value="TRUE" />
</form>

 

Hope this helps

Link to comment
Share on other sites

Another slight problem is that im trying to compare the password and password2 field.

 

the code i am using is:

if ($_POST['Password'] != $_POST['Password2'])
$errors[] = 'You forgot to confirm your password.';
{
die('The passwords did not match');
}

 

But it gives an error of:

Undefined index: Password and Undefined index: Password2

 

i might not be putting it in the right place but im not sure if thats the problem?

 

// Check for a password.
if (empty($_POST['Password'])) {
	$errors[] = 'You forgot to enter the password.';
} else {
	$mypassword = trim($_POST['Password']);
}

// Check for a password2.
if (empty($_POST['Password2'])) {
	$errors[] = 'You forgot to enter the password.';
} else {
	$mypassword2 = trim($_POST['Password2']);
}
if ($_POST['Password'] != $_POST['Password2'])
$errors[] = 'You forgot to confirm your password.';
{
die('The passwords did not match');
}

Link to comment
Share on other sites

Here it is:

 

<form action="testing2.php" method="post">
       <p align="right"><font face="Comic Sans MS">Username: 
         <input type="text" name="PatientID" size="15" maxlength="15" value="<?php if (isset($_POST['PatientID'])) echo $_POST['PatientID']; ?>" />
       </font></p>
       <p align="right"><font face="Comic Sans MS">Password: 
         <input name="Password" type="text" id="Password" value="<?php if (isset($_POST['Password'])) echo $_POST['Password']; ?>" size="15" maxlength="30" />
       </font></p>
       <p align="right"><font face="Comic Sans MS">Confirm Password: 
         <input name="Password2" type="text" id="Password2" value="<?php if (isset($_POST['Password2'])) echo $_POST['Password2']; ?>" size="15" maxlength="30" />
       </font></p>
       <p align="right"><font face="Comic Sans MS">DOB: 
         <input name="DOB" type="text" id="DOB" value="<?php if (isset($_POST['DOB'])) echo $_POST['DOB']; ?>" size="20" maxlength="40"  /> 
       </font></p>
       <p align="right"><font face="Comic Sans MS">
         <input type="submit" name="submit" value="insertingRecord" />
       </font></p>
       <div align="right"><font face="Comic Sans MS">
         <input type="hidden" name="submitted" value="TRUE" />
         </font>
          </div>
    </form>

Link to comment
Share on other sites

Another problem that has just come up.... All the input fields in my form are not necessarily text fields (i.e. when i input the gender field, it will have two options; male and female), and will require selecting radio buttons and some are drop-down boxes. Ive tried many ways but have not been successful. The code for my text fields in my form is already given in my last post.

 

Any ideas how i could work around this?

Link to comment
Share on other sites

Should work going by what you posted (the textboxes). Try putting the following bit of code on your receiving page:

<?php
echo '<pre>'."\n";
print_r( $_POST );
echo '</pre>';
?>

And paste what it outputs here (if you use real passwords don't forget to change them to something before posting.)

 

For the radiobuttons, comboboxes (and maybe later textarea's and checkboxes) I'd advice you to follow the short but useful tutorial on w3schools.

Link to comment
Share on other sites

Here is the output:

 

Array

(

    [PatientID] => 130

    [Password] => p130

    [Password2] => p130

    [DOB] => 1961-12-10

    [Age] => 48

    [sex] => male

    [Post_Code] => B26 8LK

    [Ward] => Erdington

    [submit] => insertingRecord

    [submitted] => TRUE

)

 

Link to comment
Share on other sites

Seems like the Password and Password2 fields exist.

 

Taking a look at your code again

<?php
if ($_POST['Password'] != $_POST['Password2'])
   $errors[] = 'You forgot to confirm your password.';
   {
   die('The passwords did not match');
   }
?>

You seem to be doing some odd things.

What you probably intended to do was:

<?php
if ( (isset( $_POST['Password']) && isset($_POST['Password2']) ) //If the values exist
&& $_POST['Password'] != $_POST['Password2'] )                     //and the values aren't equal.
{
    if( $_POST['Password2'] == '' ) //If the second password field was left blank.
    {
        $errors[] = 'You forgot to confirm your password.';
    }
    else //Passwords were given, but they differ.
    {   
        die('The passwords did not match');
    }
}
//Else password fields were not empty and they matched.
?>

Link to comment
Share on other sites

Thanks Axeia, that was exactly what i was trying to do. :)

 

Just another quick question, Ive looked at the tutorials on w3schools and Ive put together some code but I'm not exactly sure how to make the option selected input into the database. The code that Ive put together for radio buttons is as follows:

<?php
<font face="Comic Sans MS">Gender:</font><font face="Comic Sans MS"> Male:
                <input type="radio" value="Male" name="gender">
            Female:
            <input type="radio" value="Female" name="gender"></font>
?>

 

And the code for a combo box that Ive created is as follows:

<?php
<p align="right"><font face="Comic Sans MS"><strong>Ethnicity : </strong>
                <select name="ethnicity" size="1" ethnicity = "ethnicity">
                  <option value="A: White British">A: White British</option>
                  <option value="B: White Irish">B: White Irish</option>
                  <option value="C: Any Other White Backgound">C: Any Other White Backgound</option>
                  </select>
          </font></p>
        </div>
?>

It selects the option on the form but does not enter it into the database. for the text boxes Ive used this code:

<?php if (isset($_POST['PatientID'])) echo $_POST['PatientID']; ?>" />

but I'm not sure how to change it to make it work for radio buttons and combo boxes? Ive tried many ways but have not been successful.

Link to comment
Share on other sites

Just another quick question, Ive looked at the tutorials on w3schools and Ive put together some code but I'm not exactly sure how to make the option selected input into the database. The code that Ive put together for radio buttons is as follows:


<font face="Comic Sans MS">Gender:</font><font face="Comic Sans MS"> Male:
                <input type="radio" value="Male" name="gender">
            Female:
            <input type="radio" value="Female" name="gender"></font>

 

And the code for a combo box that Ive created is as follows:

<p align="right"><font face="Comic Sans MS"><strong>Ethnicity : </strong>
                <select name="ethnicity" size="1" ethnicity = "ethnicity">
                  <option value="A: White British">A: White British</option>
                  <option value="B: White Irish">B: White Irish</option>
                  <option value="C: Any Other White Backgound">C: Any Other White Backgound</option>
                  </select>
          </font></p>
        </div>

It selects the option on the form but does not enter it into the database. for the text boxes Ive used this code:

<?php if (isset($_POST['PatientID'])) echo $_POST['PatientID']; ?>" />

but I'm not sure how to change it to make it work for radio buttons and combo boxes? Ive tried many ways but have not been successful.

 

Is there anyone that can help me as ive been working on this but still havent got anything positive. Please help

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.