0

We are trying to complete / fix the below code, We cant seem to do the following.

  • Check if 'Check_Activation' is set to 'NULL' within the Database
  • IF value is NULL direct the user to one of the forms (1,2,3)
  • And finally if the 'Check_Activation' has already been activated and isn't 'NULL' prevent user from accessing one of the 3 forms.

I know its basicly there but we can't seem to figure out the final bug.

Please have a quick look at the code below and if anyone notices anything that isn't right please advice us.

Paste Bucket / Version
Website URL

    <?php

$username = $_POST['username'];
$activation_code = $_POST['activation_code'];
$activation_codeurl = $activation_code;
$usernameurl = $username;

$db_host = "localhost";
$db_name = "aardvark";
$db_use = "aardvark";
$db_pass = "aardvark";

$con = mysql_connect("localhost", $db_use, $db_pass);
if (!$con){
    die('Could not connect: ' . mysql_error());
}
mysql_select_db($db_name, $con);

$checkcustomer = mysql_query("SELECT `Check_Activation` FROM `members` WHERE `Username` = '".$username."' & `Activation` = '".$activation_code."'; ");

    $array = mysql_fetch_array($checkcustomer);
    if (is_null($array['Check_Activation']))  {
            $username = substr($username, 0, 1);
            if($username == '1') { 
                $redirect_url='form-one.php?membernumber='.$usernameurl.'&activation_code='.$activation_codeurl;
            } elseif($username == '2') { 
                $redirect_url='form-two.php?membernumber='.$usernameurl.'&activation_code='.$activation_codeurl;              
            } elseif($username == '3') { 
                $redirect_url='form-three.php?membernumber='.$usernameurl.'&activation_code='.$activation_codeurl;
            }
            header("Location:". $redirect_url);
    } 
    else 
    {
?>

Database Structure

1
  • You should use the MySQLi extension of PHP since the MySQL extension has been deprecated due to security issues. Commented Feb 5, 2014 at 17:51

2 Answers 2

2

Try this, You need to fetch the row from table and then you can check the values,

$val = mysql_fetch_array($checkcustomer);
if (is_null($val['Check_Activation']))

instead of

$val = mysql_query($checkcustomer);
if ($val == 'NULL')

NOTE: Use mysqli_* functions or PDO instead of using mysql_* functions(deprecated)

Sign up to request clarification or add additional context in comments.

Comments

0

before I get into the technicality of what your are trying to accomplish, I have some advice for your code in general. You should avoid using the mysql api as it is deprecated, and use the mysqli api instead. I think you will also find that it is easier to use.

Now for the code: You have this line in your code which seems to be incorrect, $checkcustomer is a result set from your previous query, so why are you running it as a query again?

$val = mysql_query($checkcustomer);

You already have the result set so do this:

$array = mysql_fetch_array($checkcustomer);

And then take the value of Check_Aviation;

if (is_null($array['Check_Aviation']))  {
    //Do Something
}

Should solve your issue

2 Comments

I tried both Krish R's and LagMasters examples but I cant seem to get this working, No matter what your typing into the form it still allows the user to acccess the next forms - awkreativ.com/freelance/analogue/barrio_activation
Any errors? Or it just goes to the next set of headers?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.