Jump to content

PHP Newbie - Help with Email Activation


McPhersonline

Recommended Posts

Hi, very new to PHP and I'm trying to get email activation down. I'm trying to set the activation field in phpMyAdmin as a BOOL, so 1=activated, 0=inactive. But I'm getting...

 

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(1) NOT NULL DEFAULT '0'' at line 1

 

Before this message, I acquired a problem. On my register page,

 

http://mcphersonline.com/aoc/register.php

 

At some point...the users I registered to test the form stopped getting logged by the database; a successful registration would bring up the message, "You have registered successfully," but I'd check the database and that user was not registered.

 

I'll post my register page's code, not including the form html at the bottom, of course.

 

<?php

echo "<h1>Register</h1>";

 

$submit = $_POST['submit'];

 

 

//form data

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

$lastname = strip_tags($_POST['lastname']);

$username = strtolower(strip_tags($_POST['username']));

$password = strip_tags($_POST['password']);

$repeatpassword = strip_tags($_POST['repeatpassword']);

$date = date("Y-m-d");

$email = $_POST['email'];

 

 

 

if ($submit)

{

$connect = mysql_connect("localhost", "p24fpt9i_boss", "mypassword");

mysql_select_db("p24fpt9i_phorum"); //select database

 

$namecheck = mysql_query("SELECT username FROM users WHERE username='$username'");

$count = mysql_num_rows($namecheck);

 

if ($count!=0)

{

die ("That username already exists. Please select a different one.");

}

 

 

//check for existence

if ($firstname&&$lastname&&$username&&md5($password)&&repeatpassword)

{

 

//check to see if password and repeat password match

if ($password==$repeatpassword)

{

//check char length of username and fullname

if (strlen($username)>25||strlen($firstname)>25||strlen($lastname)>25)

{

echo "Maximum length for username is 25 characters. This rule also applies to first and last name.";

}

else

{

//check password length

if (strlen($password)>25||strlen($password)<6)

{

echo "Password must be between 6 and 25 characters";

}

else

{

 

 

//register the user!

 

//encrypt password

$password = md5($password);

$repeatpassword = md5($repeatpassword);

 

//generate random number for activation process

$random = rand(23456789,98765432);

 

$queryreg = mysql_query("

 

INSERT INTO users VALUES ('','$firstname','$lastname','$username','$password','$email','$date','$random','0',)

 

");

 

 

echo $lastid = mysql_insert_id();

die();

 

//SEND ACTIVATION EMAIL

 

$to = $email;

$subject = "Activate your account!";

$headers = "From: admin@aoc";

$server = "mail.mcphersonline.com";

 

$body = "

 

Hello $fullname,

 

You need to activate yoru account with the link below:

http://www.mcphersonline.com/aoc/activate.php?id=$id

 

";

 

//function to send email

mail($to, $subject, $body, $headers);

 

die("You have been successfully registered! <a href='username.php'>Return to login page[/url]");

 

}

 

}

}

else

echo "Your passwords do not match!";

 

 

 

 

}

else

echo "Please fill in all fields!";

 

 

 

 

 

//close if submit

}

?>

 

 

 

 

 

 

 

 

Also, here is my activation page, though I doubt the problem lies here. Knowing me though, I'm probably 100% incorrect.

 

 

 

<?php

 

$connect = mysql_connect("localhost", "p24fpt9i_boss", "my password")

or die("Couldn't connect!");

mysql_select_db("p24fpt9i_phorum") or die("Couldn't find db");

 

 

 

 

$id = $_GET['id'];

$code = $_GET['code'];

 

if ($id&&$code)

{

 

$check = mysql_query("SELECT * FROM users WHERE ID='$id' AND random='$code'");

$checknum = mysql_num_rows($check);

 

 

 

 

if ($checknum==1)

{

 

//run a query to activate the account

$acti = mysql_query("UPDATE users SET activated='1' WHERE id='$id'");

die("Your account is activated. You may now log in.");

 

 

}

else

die("Invalid id or activation code.");

 

 

 

 

}

else

die("Data missing!");

 

?>

 

 

 

 

I've been stuck here for a while. Please help, and thank you so much in advance.

Link to comment
Share on other sites

  • 6 months later...

Where you have:

$queryreg = mysql_query("

 

INSERT INTO users VALUES ('','$firstname','$lastname','$username','$password','$email','$date','$random','0',)

 

");

 

Check the table names that are matching up with these values you are submitting:

$queryreg = mysql_query("INSERT INTO users (firstname,lastname,username,password,email,date,random) VALUES ('$firstname','$lastname','$username','$password','$email','$date','$random')") or die(mysql_error());

 

Also check here:

http://bgallz.org/24/using-php-with-email-activation/

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.