Jump to content

where am i going wrong?


chris_s_22

Recommended Posts

ok when my form is submitted it sucessfully enters the details into the database and sends the email and all seems to work fine

function user_register($username, $password, $email)
{
// Get a salt using our function
     $salt = generate_salt();
// Now encrypt the password using that salt
     $encrypted = md5(md5($password).$salt);
// Get a confirmation code
 $confirm_code=md5(uniqid(rand()));
// Get the current date
 $regdate=date("Y-m-d") ;
// checks if username in use
$query = mysql_query("SELECT * FROM user WHERE username = '". $username ."'");
if (mysql_num_rows($query) > 0)
{
// Reshow the form with an error
    $login_error = 'username already taken';
    include 'index.php';
    exit;
}

// And lastly, store the information in the database
$query = "insert into user (username, password, salt, email, confirmcode, regdate) values ('$username', '$encrypted', '$salt', '$email', '$confirm_code', '$regdate')";
    $result=mysql_query($query) or die(mysql_error());

// if suceesfully inserted data into database, send confirmation link to email 
if($result)
{
// send e-mail to ...
$to=$email;
// Your subject
$subject="Registration ... Your confirmation link here";
// Your messages and contents of the actual email 
    $message="Your Comfirmation link \r\n";
$message.="Click on this link to activate your account \r\n";
$message.="http://www.pinkangel4u.com/Agency/loginreg/conformationcheck.php?passkey=$confirm_code&user_email=$user_email";// send email
// send email
$sentmail = mail($to,$subject,$message);
}
// if not found 
else {
echo "Not found your email in our database";
}
// if your email succesfully sent
if($sentmail){
header('Location: http://www.pinkangel4u.com/Agency/loginreg/conformation.php');
}
else {
echo "Cannot send Confirmation link to your e-mail address";
}
}

in my database i have a feild named registered which is set to 0 as default. this below code is suposed to check data from the email to what was entered in the database in the above script.

if sucessful it is suposed to change the default 0 in the registered feild to a 1 however when the link in the email is clicked it directs to index.php and echo the sucessful message, though when i check my database it hasnt changed the 0 to a 1 can someone help me figure out why

<?
include('init.php');
// Passkey that got from link 
$passkey=mysql_real_escape_string($_GET['passkey']);
$user_email = mysql_real_escape_string($_GET['user_email']);
$query = "UPDATE `user` SET `registered` = '1' WHERE `confirmcode` = '" . $passkey . "'";
    if (!mysql_query($query))
    {    // handle failure
    echo "Incorrect code";
    }
    else
    {  
    // show login form with message
          $reg_checksuc = 'email verified please login';
          include 'index.php';
          exit;
    }  
?>

Link to comment
Share on other sites

Are you connecting to the DB in init.php?

echo $query and see what it returns.

use mysql_error() after your query to check for errors.

 

Your error checking is wrong.  Checking  if (!mysql_query($query)) to determine if the code is correct is not a accurate way.  Your query won't produce an error if the confirmcode doesn't exist.

Link to comment
Share on other sites

made the changes after the query im now getting the error message Incorrect code

 

im sure this has to do with what i am sending in the email

can you see what?

$message.="http://www.pinkangel4u.com/Agency/loginreg/conformationcheck.php?passkey=$confirm_code&user_email=$user_email";// send email

Link to comment
Share on other sites

ok heres a update been messing about but have realised that when a email is sent the link looks something like this

 

http://www.pinkangel4u.com/Agency/loginreg/conformationcheck.php?passkey=8d6c5d3db0bf69e9f33df79c73a28005&user_email=

 

though no matter what is written after this http://www.pinkangel4u.com/Agency/loginreg/conformationcheck.php?passkey=

if you was to put this into a browser and type something after,

 

it directs to the index.php and displays email verified please login

 

so its not checking the passkey

Link to comment
Share on other sites

OK.

 

but please post the get passkeys echos pre escape and after and if you can please echo the following code

<?php
$arr = array("_POST","_GET","_REQUEST");
foreach($arr as $k){foreach($$k as $k2=>$v){echo $k." -> ".$k2."--".$v."<BR>";}
?>

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.