Jump to content

form to db problem


barney0o0

Recommended Posts

Ive got a form that functions perfectly  locally and on two other external servers. However on the server to which the site will eventually be hosted, the form fails. There is no mysql errors, just that last handwritten error message  'fail'.

 

Ive noticed (on the host server only) that if i add a user with a name already in the table, it doesnt flag it up. So, i thought maybe its something to with the connection, however ive checked it 100+ times (and also its the same as the main dynamic data on the site, which works fine).

 

Could the script have some problem with the mysql and php version that have?

(php version is Version 4.4.0 and Server version: 3.23.58-log)

 

The only difference to the db structure is that on the host its MyISAM rather than Innob (which i cant change the value)

 

This is the last page of the site...and its really driving me mad.

Any help to get this thing work would be really appreciated

Thanks in advance

 

<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post">

          <fieldset>

<legend>Create Your Personal Account</legend>

<p>

  

  Fields marked <span class="style1">*</span> are required.</p>



<?php

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

$errors = array();

	require_once ('connection1.php');



	if (eregi('^[[:alnum:]\.\'\-]{4,30}$', stripslashes(trim($_POST['username']))) ) {

	$user = mysql_real_escape_string($_POST['username']);

	$query = "SELECT username FROM regusers WHERE username = '$user'";

	$result = @mysql_query($query);

	$num = @mysql_num_rows($result);

	if ($num> 0) {

		$errors[] = 'The username you have chosen has already been taken, please try again.';

	} else {

		$username = mysql_real_escape_string($_POST['username']);

	}

} else {

	$errors[] = 'Please provide a valid username between 4 and 30 characters.';

}





if (!eregi('^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})', stripslashes(trim($_POST['email'])) )) {

	$errors[] = 'Please provide a valid email address.';

} else {

	$email = mysql_real_escape_string($_POST['email']);

}

if (!empty($_POST['password1'])) {

	if ($_POST['password1'] != $_POST['password2']) {

		$errors[] = 'The 2 passwords you have entered do not match.';

	} else {

		$password = $_POST['password1'];

	}

} else {

	$errors[] = 'Please provide a password.';

}





//define the oterh fields

$firstname = mysql_real_escape_string($_POST['firstname']);

$surname = mysql_real_escape_string($_POST['surname']);

$nostreet = mysql_real_escape_string($_POST['nostreet']);

$town = mysql_real_escape_string($_POST['town']);

$city = mysql_real_escape_string($_POST['city']);

$postcode = mysql_real_escape_string($_POST['postcode']);

$updates = mysql_real_escape_string($_POST['updates']);









if (empty($errors)) {

			$a = md5(uniqid(rand(), true));

	$query = "INSERT INTO regusers (username, email, password, active, postcode, city, town, nostreet, surname, firstname, updates) VALUES ('$username', '$email', SHA('$password'), '$a', '$postcode', '$city', '$town', '$nostreet', '$surname','$firstname', '$updates')";



	$result = @mysql_query($query);

	if (mysql_affected_rows() == 1) {

					// Send the E-Mail

					$body = "Thank you for registering . To activate your account, please click on this link:\n\n";

			$body .= "http://www.whateveraddressyouwanthere.com/activate.php?x=" . mysql_insert_id() . "&y=$a";

		mail($_POST['email'], 'Registration Confirmation', $body, 'From: email@host');

					// Show thank you message

		echo '<h3>Thats it!</h3>

		welcome.';

	} else {

		echo 'fail.';

	}

	} else {

	echo '<h2>Error!</h2>

	The following error(s) occured:<br /><br />';

	foreach ($errors as $msg) {

		echo "$msg <br />\n";

	}

}

}

?>

<dl>







<dt><label for="username">User Name*</label>

</dt>

<dd><input type="text" name="username" id="username" value="<?php if (isset($_POST['username'])) echo $_POST['username']; ?>"  maxlength="30"class="borders" tabindex-"2" />

</dd>

<dt><label for="password2">Password*</label>

</dt>

<dd><input type="password" name="password1" id="password1" class="borders" tabindex-"3" />

</dd>



<dt><label for="message">Repeat Password*</label></dt>

<dd><input type="password" name="password2" id="password2" class="borders" tabindex-"3" />

</dd>







</dl>



</fieldset>

<fieldset>

<legend>Contact Information</legend>



<dl>





<dt><label for="username">First Name*</label>

</dt>

<dd><input type="text" name="firstname" id="firstname" value="<?php if(isset($_POST['firstname'])) echo $_POST['firstname']; ?>"class="borders" tabindex-"2" />

</dd>

<dt><label for="username">Surname*</label>

</dt>

<dd><input type="text" name="surname" id="surname" value="<?php if(isset($_POST['surname'])) echo $_POST['surname']; ?>"class="borders" tabindex-"2" />

</dd>



<dt><label for="username">Email Address*</label>

</dt>

<dd><input type="text" name="email" id="email" value="<?php if(isset($_POST['email'])) echo $_POST['email']; ?>"class="borders" tabindex-"2" />

</dd>

<dt><label for="password2">House No., Street</label>

</dt>

<dd><input type="text" name="nostreet" id="nostreet" value="<?php if(isset($_POST['nostreet'])) echo $_POST['nostreet']; ?>"class="borders" tabindex-"3" />

</dd>



<dt><label for="password2">Town</label>

</dt>

<dd><input type="text" name="town" id="town" value="<?php if(isset($_POST['town'])) echo $_POST['town']; ?>"class="borders" tabindex-"3" />

</dd>

<dt><label for="password2">City</label>

</dt>

<dd><input type="text" name="city" id="city" value="<?php if(isset($_POST['city'])) echo $_POST['city']; ?>"class="borders" tabindex-"3" />

</dd>

<dt>

  <label for="password2">Postcode</label>

</dt>

<dd><input type="text" name="postcode" id="postcode" value="<?php if(isset($_POST['postcode'])) echo $_POST['postcode']; ?>"class="borders"  tabindex-"3" />

</dd>

<dt>

  <label for="updates">I am happy to recieve information from other organisations </label>

</dt>

<dd><input type="checkbox" name="updates" id="updates" value="y" tabindex="5"/>

</dd>









</dl>



</fieldset>

<input type="submit" name="submit" value="Register" tabindex="6"/>

<input type="hidden" name="submitted" value="TRUE" />

        </form>

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.