Jump to content

Quick fix - form entering blank records - same old problem


Recommended Posts

I know this problem comes up a lot but it can be for various reasons so after reading up I can't decide what might be wrong. I'm still learning!

I have a simple php registration form (first name, second name, email address) and every time a user submits an entry a second blank record is created in the MYSQL database after it.

 

Any help would be great. (php code in red)

 

 

[color=red]<?
$firstname=$_POST['firstname'];
$surname=$_POST['surname'];
$email=$_POST['email'];

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$query = "INSERT INTO register VALUES ('','$firstname','$surname','$email')";
mysql_query($query);

mysql_close();
?>[/color]

 

 

Here is the section on the html HTML page that submits the form

 

 <form action="register.php" method="post" class="BagTitle">
        <table width="700" border="0" cellpadding="0" cellspacing="2">
	  <tr>
	    <td width="100">First Name: </td>
	    <td width="594"><input name="firstname" type="text" size="50" /></td>
      </tr>
	  <tr>
	    <td>Last Name: </td>
	    <td><input name="surname" type="text" size="50" /></td>
      </tr>
	  <tr>
	    <td>E-mail:</td>
	    <td><input name="email" type="text" size="50" /></td>
      </tr>
	  <tr>
	    <td colspan="2"> </td>
      </tr>
	  <tr>
	    <td colspan="2"><input type="Submit" value="Send" />
        <input name="Reset" type="reset" value="Reset Form" /></td>
      </tr>
    </table>
      </form></p>

 

Also I have no idea about securing this information. Are there any basic steps I can take?

 

 

 

I've just discovered that it doesn't add the extra blank record in if the user is using internet explorer. I was testing it with Firefox (it definitely does add in a blank record after the new one.

 

Does this help? I'm still a bit lost on how to fix this????

Firefox will request a page twice due to using debugging add-ons and at least in the past it would request a page twice if the default character encoding you have set in the browser does not match the character encoding on the page.

I really have no idea how to fix this. I have seen other cases when searching around where just a couple of unnecessary <td> tags in the html have caused the browser to refresh and send the data twice - once properly and once with just blank fields.

 

Does anyone have any ideas?

 

Even if there isn't a way of stopping firefox refreshing, can I just say in the php code - don't send to the database if fields are empty or if button hasn't actually been clicked. This would then surely fix the problem???

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.