jacob21 Posted November 6, 2014 Share Posted November 6, 2014 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) : ''); Quote Link to comment https://forums.phpfreaks.com/topic/292316-help-with-referring-system/ Share on other sites More sharing options...
ginerjm Posted November 6, 2014 Share Posted November 6, 2014 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? Quote Link to comment https://forums.phpfreaks.com/topic/292316-help-with-referring-system/#findComment-1495927 Share on other sites More sharing options...
jacob21 Posted November 6, 2014 Author Share Posted November 6, 2014 (edited) <?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 November 6, 2014 by jacob21 Quote Link to comment https://forums.phpfreaks.com/topic/292316-help-with-referring-system/#findComment-1495930 Share on other sites More sharing options...
jacob21 Posted November 6, 2014 Author Share Posted November 6, 2014 How to remember ref and ref_id and print out detected values? I need to refresh page to get cookie value if i use this code if(!empty($_GET['ref'])){ setcookie('ref', $_GET['ref'], time() + 60 * 60 * 24 * 3); } print $_COOKIE['ref'] Quote Link to comment https://forums.phpfreaks.com/topic/292316-help-with-referring-system/#findComment-1495937 Share on other sites More sharing options...
ginerjm Posted November 7, 2014 Share Posted November 7, 2014 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. Quote Link to comment https://forums.phpfreaks.com/topic/292316-help-with-referring-system/#findComment-1496023 Share on other sites More sharing options...
cyberRobot Posted November 7, 2014 Share Posted November 7, 2014 (edited) 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 November 7, 2014 by cyberRobot Quote Link to comment https://forums.phpfreaks.com/topic/292316-help-with-referring-system/#findComment-1496029 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.