Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4076578
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T17:26:35+00:00 2026-05-20T17:26:35+00:00

The following is my problem (example code).. If I perform this: $rf = $_GET[‘_id’];

  • 0

The following is my problem (example code)..

If I perform this:

$rf = $_GET['_id'];

if($_POST['form']){
echo "ref: " . $rf;
}

$rf is blank during if($_POST['form'])

Now, If I perform this:

$rf = "123456";

if($_POST['form']){
echo "ref: " . $rf;
}

$rf is displayed

Why is it blank the first time and not blank if I assign something static to the $rf var?
Also how can I fix this so the first solution works?

Thanks!

Note: don’t worry about SQL injections.. I have already stripped everything from “_id”.

Complete PHP and HTML

<?php

require "includes/connect.php";
//var_dump($_GET);die;

function gen_code($codeLen = 7) {     
$code = '';     
for ($i=0; $i<$codeLen; $i++) {         
 $d=rand(1,30)%2;       
 $code .= $d ? chr(rand(65,90)) : chr(rand(48,57));      }  
 return $code; 
 }  


 function add_code($email_id) {
 global $mysqli;
 $code = gen_code(7); 
 $mysqli->query("UPDATE coming_soon_emails SET code='" . $code ."' WHERE email_id='" . $email_id . "'");  
 if($mysqli->affected_rows != 1) {   
 add_code($email_id);  
 } else return $code; } 

$msg = '';
$referrer = $_GET['_url'];
// echo $referrer displays the referrer ID contents correctly

if ( ! empty($referrer))
{
$mysqli->query("UPDATE coming_soon_emails SET clicks = clicks + 1 WHERE code='" . $referrer ."'");
}

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


    // Requested with AJAX:
    $ajax = ($_SERVER['HTTP_X_REQUESTED_WITH']  == 'XMLHttpRequest');

    try{
        if(!filter_input(INPUT_POST,'email',FILTER_VALIDATE_EMAIL)){
            throw new Exception('Invalid Email!');
        }

        $mysqli->query("INSERT INTO coming_soon_emails
                        SET email='".$mysqli->real_escape_string($_POST['email'])."'");

        if($mysqli->affected_rows != 1){
            throw new Exception('This email already exists in the database.');
        } else {   
          $email_code = add_code($mysqli->insert_id); 
        } 

        $msg = "http://www.my-url/" . $email_code;

        //the following doesn't work as referrer is now empty :(
        if ( ! empty($referrer))
        {
        $mysqli->query("UPDATE coming_soon_emails SET signup = signup + 1 WHERE code='" . $referrer ."'");
        }

        if($ajax){
            die(json_encode(array('msg' => $msg)));
        }

    }
    catch (Exception $e){

        if($ajax){
            die(json_encode(array('error'=>$e->getMessage())));
        }

        $msg = $e->getMessage();        
    }
}

?>


<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>

<link rel="stylesheet" type="text/css" href="css/styles.css" />

</head>

<body>

<div id="launch">


    <form id="form" method="post" action="">
        <input type="text" id="email" name="email" value="<?php echo $msg;?>" />
        <input type="submit" value="Submit" id="submitButton" />
    </form>

    <div id="invite">
    <p style="margin-top:20px;">The ID of who referred you: <?php echo $referrer; //this displays correctly?>)</p>
    <p style="margin-top:20px;"><span id="code" style="font-weight:bold;">&nbsp;</span></p>
    </div>


</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js"></script>
<script src="js/script.js"></script>
</body>
</html>

script.js

$(document).ready(function(){

    // Binding event listeners for the form on document ready

    $('#email').defaultText('Your Email Address');

    // 'working' prevents multiple submissions
    var working = false;

    $('#form').submit(function(){

        if(working){
            return false;
        }
        working = true;

        $.post("./index.php",{email:$('#email').val()},function(r){

            if(r.error){
                $('#email').val(r.error);
                        } else {
                $('#email').val(r.msg);
            }


            working = false;
        },'json');

        return false;
    });
});

// A custom jQuery method for placeholder text:

$.fn.defaultText = function(value){

    var element = this.eq(0);
    element.data('defaultText',value);

    element.focus(function(){
        if(element.val() == value){
            element.val('').removeClass('defaultText');
        }
    }).blur(function(){
        if(element.val() == '' || element.val() == value){
            element.addClass('defaultText').val(value);
        }
    });

    return element.blur();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T17:26:35+00:00Added an answer on May 20, 2026 at 5:26 pm

    $_GET[‘_id’] is apparently empty in your code.

    you are loading no example.com/5ABH67L url.
    you are loading /index.php as it’s clearly seen from script.js.

    you have to either

    • add current url to POST data using javascript.
    • or make POST action not index.php but current location.

    I am not a JS pro, but try this:

    $.post("",{email:$('#email').val()},function(r)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Following Problem: I need something like an empty scope. Which means that this scope
I have the following problem: I have an HTML textbox ( <input type=text> )
I have the following problem using subversion: I'm currently working on the trunk of
I have the following problem using template instantiation [*]. file foo.h class Foo {
I have got the following problem since the server has safe mode turned on,
I have the following problem in my Data Structures and Problem Solving using Java
Has anyone encountered the following problem: I have IIS7 running on my computer. On
I have the following problem: I open the dialog, open the SIP keyboard to
I have the following problem. If I query values with a keyfigure which is
I'm having the following problem. I created a application context file for spring.net. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.