Jump to content

Recommended Posts

<?php
case 'register':

		$addr = $_SERVER['REMOTE_ADDR'];
		$username = $_POST['username'];
		$password = $_POST['password'];
		$cpassword = $_POST['cpassword'];
		$email = $_POST['email'];
		$cemail = $_POST['cemail'];
		$challenge = $_POST['recaptcha_challenge_field'];
		$response = $_POST['recaptcha_response_field'];

		if(empty($addr) || empty($username) || empty($password) || empty($cpassword) || empty($email) || empty($cemail) || 
				empty($challenge) || empty($response))
		{
			echo "<script>window.location.href='index.php?m=register&e=0'</script>";
			exit;
		}

		$checkmultipleusers = mysql_query("SELECT * FROM users WHERE username='$username'");
		if(mysql_num_rows($checkmultipleusers) >= 1)
		{
			echo "<script>window.location.href='index.php?m=register&e=1'</script>";
			exit;
		}

		if($password != $cpassword)
		{
			echo "<script>window.location.href='index.php?m=register&e=2'</script>";
			exit;
		}

		if($email != $cemail)
		{
			echo "<script>window.location.href='index.php?m=register&e=3'</script>";
			exit;
		}

		require_once('includes/recaptchalib.php');
		$privatekey = "...";
		$resp = recaptcha_check_answer ($privatekey, $addr, $challenge, $response);

		if (!$resp->is_valid) 
		{
			echo "<script>window.location.href='index.php?m=register&e=4'</script>";
			exit;
		}

		$activationcode = md5($username);
		$registerdate = date("F j, Y");

		$registeruser = mysql_query("INSERT INTO users (`id`, `permissions`, `registerdate`, `username`, `password`, `email`, `ip`, `secondip`, `thirdip`, `fourthip`, `fifthip`, `activation`, `ipflag`) VALUES (NULL, '0', $registerdate, $username, $password, $email, $addr, '', '', '', '', '$activationcode', '0')");
		if($registeruser)
		{
			$_SESSION['username'] = $username;
			echo "<script>window.location.href='index.php?m=home'</script>";
		}
		else
		{
			echo "Something went wrong.";
			exit;
		}

	break;

 

Even if all of the error checks pass, the MySQL will not insert the information in to the table.. not even partial.

Link to comment
https://forums.phpfreaks.com/topic/71275-php-script-not-inserting-data/
Share on other sites

string values in the query, such as $username, $password etc need single quotes

 

eg INSERT INTO tablename (user,pwd) VALUES ('$username', '$password');

 

If, when you use mysql_query() you trap for error messages, it tells you thing like this.

 

$result = mysql_query(...) or die(mysql_error());

string values in the query, such as $username, $password etc need single quotes

 

eg INSERT INTO tablename (user,pwd) VALUES ('$username', '$password');

 

If, when you use mysql_query() you trap for error messages, it tells you thing like this.

 

$result = mysql_query(...) or die(mysql_error());

Ah, so obvious, thank you.

 

I haven't coded PHP in a couple of years, still rusty on some of the finer details.

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.