Jump to content

Recommended Posts

I was on earlier today with a topic that wound up in the HTML help section.  After further debugging and testing I have realized that the error lay somewhere else and is a PHP problem.  And now I'm stuck.  If someone solves this, they can PM their email address and I'll send them $10 via paypal.

 

The short: I created a site registration page.  I did not like the old boring gray "submit" form box, so I replaced it with a image file.  Before I did this, my registration work for safari, firefox, chrome and IE8.  After switching to a custom picture file for the form submission button, it ceased to work in IE8.  When one presses the button, the variables are not set and the form is wiped clean.

 

Here's the full 81 line registration php file.  First a quick guide:

losidebar.php contains a side column stuff (<div id=sidecolumn>...</div>).

connect4.php contains the necessary information to connect to mysql.

header.php and footer.php are the first and last pieces of my html page when finished.

<?php 
  // Insert the page name
  $page_title = 'Registration';
  require_once('header.php');
  require_once('losidebar.php');
  require_once('connect4.php');
  // Connect to the database
  $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME);
  if (isset($_POST['submit'])) {
    // Grab the profile data from the POST
    $email = mysqli_real_escape_string($dbc, trim($_POST['email']));
$firstName = mysqli_real_escape_string($dbc, trim($_POST['firstName']));
$lastName = mysqli_real_escape_string($dbc, trim($_POST['lastName']));
    $password1 = mysqli_real_escape_string($dbc, trim($_POST['password1']));
    $password2 = mysqli_real_escape_string($dbc, trim($_POST['password2']));
    if (!empty($email) && !empty($firstName) && !empty($lastName) && !empty($password1) && !empty($password2) && ($password1 == $password2)) 
  {
	//Check to see if the email address is valid and not phony
	if(!filter_var($email, FILTER_VALIDATE_EMAIL))
	   {
		echo '<div id="mainContent">';
		echo "Email is not valid. <br />";
		echo "<a href=\"signup.php\">Try Again</a>. <br /></div>";
		require_once('footer.php');
		exit;
	   }
	else {				 
		// Person has submitted data in all three fields. Passwords match. No phony email.
		// Call Stored Procedure spRegister
		// If email is unique, returns the member's id
		// If email is not unique, nothing is returned
		$encrypt = sha1($password1);
		$query = "CALL mealshare.spRegister('$email','$encrypt', '$firstName', '$lastName')"; 
		$data = mysqli_query($dbc,$query) or die('Error connecting to the database');
		$numrows = mysqli_num_rows($data);
		if ($numrows == 0) {
			// An account already exists for this email address, so display an error message
			echo '<div id="mainContent">';
			echo '<p>The email address' . " " . "$email" . " " . 'has already been registered with our site.<br />';
			echo '<p>If that was you, <a href="index.php">login</a> with it now.</p></div>';
			require_once('footer.php');
			exit;
			}
		$row = mysqli_fetch_array($data);			
		$memberid = $row['memberID'];
		mysqli_close($dbc);
		// Redirect to a success page
		$home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) 		. 'success.php';
		header('Location: ' . $home_url);
		exit();
	   }
   }
else {
	//Data does not match.  Either password 1&2 not the same or a required field(s) is blank.
	echo '<p>Seems you have made a mistake.  Please try again.  Don\'t forget to fill in all the forms.</p>';
	  }
  }
mysqli_close($dbc);
?>
  <div id="mainContent">
  <p>You will need to enter a valid email address.  This will be your username.</p>
  <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <fieldset>
      <legend>It's that easy!</legend>
      <table border="0">
      <tr><td><label for="email">Email:</label></td>
      <td><input type="text" id="email" name="email" value="<?php echo $email; ?>" /></td></tr>
      <tr><td><label for="firstName">First Name:</label></td>
      <td><input type="text" id="firstName" name="firstName" value="<?php echo $firstName; ?>" /></td></tr>
      <tr><td><label for="lastName">Last Name:</label></td>
      <td><input type="text" id="lastName" name="lastName" value="<?php echo $lastName; ?>" /></td></tr>
      <tr><td><label for="password1">Password:</label></td>
      <td><input type="password" id="password1" name="password1" /></td></tr>
      <tr><td><label for="password2">Password (retype):</label></td>
      <td><input type="password" id="password2" name="password2" /></td></tr></table>
    </fieldset><input type="image" width="157" height="60" border="0" value="Sign Up" name="submit" src="images/signup_submit.gif"/></form>
<!-- end #mainContent --></div>
<!-- This clearing element should immediately follow the #mainContent div in order to force the #container div to contain all child floats --><br class="clearfloat" />
<?php require_once('footer.php'); ?>
</body> 
</html>

 

What I've done thus far: I created a blank php file and copied just the form into this new file.  I used the same image file on the same folder on the server (and, likewise, held every other variable constant I could think of).  On this page, the special submit button works!

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="layout_01.css" rel="stylesheet" type="text/css" />
</head>
<body>

<?php

$email = $_POST['email'];
$first = $_POST['firstName'];
$last = $_POST['lastName'];
$password1 = $_POST['password1'];
$password2 = $_POST['password2'];

echo $email;
echo $first;
echo $last;
echo $password1;
echo $password2;

?>

  <p>You will need to enter a valid email address.  This will be your username.</p>
  <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <fieldset>
      <legend>It's that easy!</legend>
      <table border="0">
      <tr><td><label for="email">Email:</label></td>
      <td><input type="text" id="email" name="email" value="<?php echo $email?>"/></td></tr>
      <tr><td><label for="firstName">First Name:</label></td>
      <td><input type="text" id="firstName" name="firstName" value="<?php echo $first?>"/></td></tr>
      <tr><td><label for="lastName">Last Name:</label></td>
      <td><input type="text" id="lastName" name="lastName" value="<?php echo $last?>"/></td></tr>
      <tr><td><label for="password1">Password:</label></td>
      <td><input type="password" id="password1" name="password1" value="<?php echo $password1?>"/></td></tr>
      <tr><td><label for="password2">Password (retype):</label></td>
      <td><input type="password" id="password2" name="password2" value="<?php echo $password2?>"/></td></tr></table>
    </fieldset><input type="image" width="157" height="60" border="0" value="Sign Up" name="submit" src="images/signup_submit.gif"/>
    
  </form>

</body> 
</html>

 

My $10 question is why is my code not working for IE on my registration page?  What is the inconsistency between the two pages?

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/202412-form-submission-error-with-my-php/
Share on other sites

Yes, that's the problem.  Only in IE is there a problem (and 8 is all I have at my disposal to try).  I did just try action="" and that didn't fix the IE issue.  I did confirm that when the code is action="" it still works in FF.

 

And, even though it is only in IE, when I did that second page, my 2nd set of code in the parent post, it worked for IE.  That's why I'm so baffled.

Aha!  I just took this piece of code from my registration page:

 

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

 

and added it to the 2nd page.  I just broke the second page in IE, but it's not broken in firefox.  There's the problem.

 

The $10 is off.  But the thread is still open.  Why is IE not liking that?

So now I've been able to isolate the problem down to just a tiny bit of code.  Any smart php vets know why this works in chrome and safari and firefox but not in IE?

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="layout_01.css" rel="stylesheet" type="text/css" />
</head>
<body>

<?php
if (isset($_POST['submit'])) {
$email = $_POST['email'];
$first = $_POST['firstName'];
$last = $_POST['lastName'];
$password1 = $_POST['password1'];
$password2 = $_POST['password2'];

echo $email;
echo $first;
echo $last;
echo $password1;
echo $password2;
}
?>

  <p>You will need to enter a valid email address.  This will be your username.</p>
  <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>">
    <fieldset>
      <legend>It's that easy!</legend>
      <table border="0">
      <tr><td><label for="email">Email:</label></td>
      <td><input type="text" id="email" name="email" value="<?php echo $email?>"/></td></tr>
      <tr><td><label for="firstName">First Name:</label></td>
      <td><input type="text" id="firstName" name="firstName" value="<?php echo $first?>"/></td></tr>
      <tr><td><label for="lastName">Last Name:</label></td>
      <td><input type="text" id="lastName" name="lastName" value="<?php echo $last?>"/></td></tr>
      <tr><td><label for="password1">Password:</label></td>
      <td><input type="password" id="password1" name="password1" value="<?php echo $password1?>"/></td></tr>
      <tr><td><label for="password2">Password (retype):</label></td>
      <td><input type="password" id="password2" name="password2" value="<?php echo $password2?>"/></td></tr></table>
    </fieldset><input type="image" width="157" height="60" border="0" value="Sign Up" name="submit" src="images/signup_submit.gif"/>
    
  </form>

</body> 
</html>

Final comment from me, I promise.  Just so we're all clear now, with the if(isset($_POST piece added to the code, IE will work if I use the original boring old gray type="submit" in a form, but not when I use a type="image" (though the other major browsers will work in either situation).  I guess this has become a html question again, sorta...

Sorry about that.  At the time I started this thread, I did not think the issue would wrap back into the first thread like it has.  I had created the new page and had the form working properly, which led me to believe I had an error somewhere in my php.  I'm going to go back to your response in the other thread and try to figure it out once again.

In your test form, add this just before you look at $_POST:

 

<?php
echo '<PRE>'; print_r($_POST); echo '</PRE>';

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

 

I think you will see that "submit" is not defined in IE.  I'm not sure, but I think this is one thing they actually do according to the spec.  In other browsers the "submit" is passed (if I remember correctly) but IE sends only the X and Y position of the mouse within the image.  Look at what keys are being consistently set in $_POST between the different browsers and decide how to figure out if the form was posted.  You might even consider just using if (isset($_POST)) since $_POST should not exist unless the form was actually posted.

I changed it to:

 

if ((isset($_POST['submit_x'])) || (isset($_POST['submit']))) {

 

and now it works in all browsers.

 

Thanks to PFMaBiSmad for his earlier help, which I did not fully understand until now.

 

http://www.phpfreaks.com/forums/index.php/topic,298638.msg1414138.html#msg1414138

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.