Jump to content

Help with referring system


jacob21

Recommended Posts

I have 2 referring url.

 

USERNAME

http://testsite.com/index.php?do=register&ref=test

USER ID

http://testsite.com/index.php?do=register&ref_id=1

 

1. Code to remember  ref and ref_id

2. Code to allow user to insert own referrer if no ref link detected?

3. Store ref and ref_id into same column Like db referrer = username/user_id or referrer = username / referrer_id = user_id ?

 

PHP

$ref_id = isset($_GET['ref_id']) ? filter_input(INPUT_GET, 'ref_id', FILTER_SANITIZE_STRING) : '');
$ref = isset($_GET['ref']) ? filter_input(INPUT_GET, 'ref', FILTER_SANITIZE_STRING) : '');

FORM

if(!empty($_GET['ref_id'])){
    print '
	<tr>
    	<td style="font-weight:bold">Referred by user id #</td>
    	<td><input type="text" name="ref_id" maxlength="255" style="width:200px" value="'.cleanOutput($ref_id).'"></td>
  	</tr>';
	
}else{
    print '
	<tr>
    	<td style="font-weight:bold">Referred by</td>
    	<td><input type="text" name="ref" maxlength="255" style="width:200px" value="'.cleanOutput($ref).'"></td>
  	</tr>';
	
}

2. 

$ref = isset($_GET['ref']) ? filter_input(INPUT_GET, 'ref', FILTER_SANITIZE_STRING) : (isset($_POST['ref']) ? filter_input(INPUT_POST, 'ref', FILTER_SANITIZE_STRING) : '');
Link to comment
Share on other sites

I have no idea what you want from us.  But I will comment.

 

1 - I hate when people post pieces of code in separate blocks.  We can't see how these pieces connect; we can't see what order they are in; we can't see if one corrupts the other.  And you dont' tell us how they interact.

 

2 - I hate when people don't see the obvious.  In your case you have some code that is grabbing two inputs.  Then you have (apparently) some code to display an INCOMPLETE(?) html table to grab these inputs.  THEN you have some code that grabs these same two inputs again.  Uhhh - is there a problem here?

 

3 - Most of all I hate when posters don't ask a clear question.  We have no idea what you are doing.  Could you spare some time and write a complete (brief?) description of your problem/question instead of making 3 numbered statements and leaving us hanging?

 

PS - if I am assuming correctly ( and I hate to assume) it is not a good idea ever to be combining separate pieces of incoming data into one column of a table.  If the data IS separate, why would you want to join it together?

Link to comment
Share on other sites


<?php
// define variables with the value for each field
// the value from POST,GET if this exist, or an empty value
$errors = array();
$username = isset($_POST['username']) ? filter_input(INPUT_POST, 'username', FILTER_SANITIZE_STRING) : '';
$ref_id = isset($_GET['ref_id']) ? filter_input(INPUT_GET, 'ref_id', FILTER_SANITIZE_STRING) : '';
$ref = isset($_GET['ref']) ? filter_input(INPUT_GET, 'ref', FILTER_SANITIZE_STRING) : '';

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

if(empty($username)){
$errors[] = 'Empty username!';
}
if(userIdExists($ref_id, $db) === FALSE){
$errors[] = 'User id wont exist';
}
if(usernameExists($ref, $db) === FALSE){
$errors[] = 'referrer wont exist';
}

}

if(!empty($_POST['submit']) and empty($errors)){

print' username = '.$username.'<br>Ref = '.$ref.'<br>Ref_id = '.$ref_id.' ';

}

if(!empty($errors)){
foreach($errors as $error){
print $error.'<br>';
}
}

print '
<form method="POST">
<table style="width:100%">
<tr>
<td style="width:30%;font-weight:bold">Username</td>
<td style="width:70%"><input type="text" name="username" maxlength="255" style="width:200px" value="'.$username.'"></td>
</tr>';

if(!empty($_GET['ref_id'])){

print '
<tr>
<td style="font-weight:bold">Referred by user id #</td>
<td><input type="text" name="ref_id" maxlength="255" style="width:200px" value="'.$ref_id.'"></td>
</tr>';

}else{

print '
<tr>
<td style="font-weight:bold">Referred by</td>
<td><input type="text" name="ref" maxlength="255" style="width:200px" value="'.$ref.'"></td>
</tr>';

}

print '
<tr>
<td colspan="2" style="text-align:center"><input type="submit" name="submit" value="Submit"></td>
</tr>
</table>
</form>';

?>

 

Edited by jacob21
Link to comment
Share on other sites

Rather than attempt to diagnose your code I just want to say:

 

1 you can't use both GET and POST in one 'submit' Whatever you placed in your form tag is what you're going to get.

2 - Your latest post - is that supposed to be the long-sought question I asked for?  What do you mean by remember?  Remember for the next submission or remember for the next 10 years?  Makes a difference.  If you mean the next submissions then how about storing the values (once you get them) in the $_SESSION array?  That way you have them for the life of your session.  Or you could just send them back out to your form the next time you output it as hidden vars which will then come back to you as POST or GET vars on the next submit.  As for saving them for 10 years or whatever, try a db save.

 

Also - read thru your code your code and ask yourself "what am I doing with these lines" at each point in your process as well as "does it make sense to be doing this here and now".  You need to get a handle on what your script s/b doing when it starts up and at various points in the process.

Link to comment
Share on other sites

1 you can't use both GET and POST in one 'submit' Whatever you placed in your form tag is what you're going to get.

 

Just to clarify, you can submit both GET and POST variables through a form. Here is a quick example:

<?php
if(isset($_POST['submit'])) {
    print '<pre>' . print_r($_GET, true) . '</pre>';
    print '<pre>' . print_r($_POST, true) . '</pre>';
}
?>
<form method="post" action="?getVar=howdy">
<label>Post Var: <input type="text" name="postVar"></label>
<input type="submit" name="submit">
</form>

Sorry if this has nothing to do with the question at hand. I haven't had the time to go through the posts.

Edited by cyberRobot
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.