seany123 Posted January 24, 2010 Share Posted January 24, 2010 i have a register page which on the end i have added ?ref=1 so its register.php?ref=1 now inside the page i have this code: $_GET['ref'] = $ref_id; echo $ref_id; why isnt it echoing 1? Quote Link to comment Share on other sites More sharing options...
jmr3460 Posted January 24, 2010 Share Posted January 24, 2010 Shouldn't it be: $ref_id = $_GET['ref']; Are you setting the variable value? Quote Link to comment Share on other sites More sharing options...
jl5501 Posted January 24, 2010 Share Posted January 24, 2010 do you mean to do this? $ref_id = $_GET['ref']; echo $ref_idl; Quote Link to comment Share on other sites More sharing options...
seany123 Posted January 24, 2010 Author Share Posted January 24, 2010 oh i didnt realise it made a difference which way it was written! thanks! Quote Link to comment Share on other sites More sharing options...
jl5501 Posted January 24, 2010 Share Posted January 24, 2010 When assigning variables, you are setting the variable on the left of the = to the value on the right. Quote Link to comment Share on other sites More sharing options...
seany123 Posted January 24, 2010 Author Share Posted January 24, 2010 that worked but its not working properly: i have this piece of code-> $insert['username'] = $_POST['username']; $insert['name'] = $_POST['username']; $insert['password'] = $password; $insert['email'] = $_POST['email']; $insert['registered'] = time(); $insert['last_active'] = time(); $insert['ip'] = $_SERVER['REMOTE_ADDR']; $insert['validkey'] = $string; if ($_GET['ref'] >= 1){ $insert['ref'] = $ref_id; } $query = $db->autoexecute('players', $insert, 'INSERT'); but its not setting ref to $ref_id. Quote Link to comment Share on other sites More sharing options...
jl5501 Posted January 24, 2010 Share Posted January 24, 2010 I cannot see in that code where you are setting $ref_id to $_GET['ref'] Quote Link to comment Share on other sites More sharing options...
seany123 Posted January 24, 2010 Author Share Posted January 24, 2010 i have it set at the top of that page... but it is set. Quote Link to comment Share on other sites More sharing options...
jl5501 Posted January 24, 2010 Share Posted January 24, 2010 I would have expected to see if ($_GET['ref'] >= 1) { $ref_id = $_GET['ref']; $insert['ref'] = $ref_id; } or even if ($_GET['ref'] >= 1) { $insert['ref'] = $_GET['ref']; } Quote Link to comment Share on other sites More sharing options...
seany123 Posted January 24, 2010 Author Share Posted January 24, 2010 I would have expected to see if ($_GET['ref'] >= 1) { $ref_id = $_GET['ref']; $insert['ref'] = $ref_id; } or even if ($_GET['ref'] >= 1) { $insert['ref'] = $_GET['ref']; } okay i have replaced it inside the if statement like you showed.. ill give it a test and see what happens. <?php $insert['username'] = $_POST['username']; $insert['name'] = $_POST['username']; $insert['password'] = $password; $insert['email'] = $_POST['email']; $insert['registered'] = time(); $insert['last_active'] = time(); $insert['ip'] = $_SERVER['REMOTE_ADDR']; $insert['validkey'] = $string; if ($_GET['ref'] >= 1) { $ref_id = $_GET['ref']; $insert['ref'] = $ref_id; } $query = $db->autoexecute('players', $insert, 'INSERT'); ?> Quote Link to comment Share on other sites More sharing options...
seany123 Posted January 24, 2010 Author Share Posted January 24, 2010 okay i have tried it with a echo straight after the if statement and the echo never showed. Quote Link to comment Share on other sites More sharing options...
jl5501 Posted January 24, 2010 Share Posted January 24, 2010 That would suggest that $_GET['ref'] has no value try print_r($_GET) to see what you have in there Quote Link to comment Share on other sites More sharing options...
seany123 Posted January 24, 2010 Author Share Posted January 24, 2010 That would suggest that $_GET['ref'] has no value try print_r($_GET) to see what you have in there when i set ?ref=1 i get this: Array ( [ref] => 1 ) when i set ?ref=5 i get this: Array ( [ref] => 5 ) Quote Link to comment Share on other sites More sharing options...
MadTechie Posted January 24, 2010 Share Posted January 24, 2010 ?ref=10 if ($_GET['ref'] >= 1){ $insert['ref'] = $_GET['ref']; } echo $insert['ref']; should result in 10 Quote Link to comment Share on other sites More sharing options...
jl5501 Posted January 24, 2010 Share Posted January 24, 2010 Ok so, that means that ref is being set. So, let us make sure that the $insert array is being populated correctly Just before you call the query, do print_r($insert) to see what is getting in there Quote Link to comment Share on other sites More sharing options...
seany123 Posted January 24, 2010 Author Share Posted January 24, 2010 ?ref=10 if ($_GET['ref'] >= 1){ $insert['ref'] = $_GET['ref']; } echo $insert['ref']; should result in 10 that didnt echo anything for me. Ok so, that means that ref is being set. So, let us make sure that the $insert array is being populated correctly Just before you call the query, do print_r($insert) to see what is getting in there i put it just before the if statement and got: Array ( [username] => sean2 [name] => sean2 [password] => md5 password => ss2@mafiakiller.com [registered] => 1264375687 [last_active] => 1264375687 [ip] => 94.2.58.23 ) Quote Link to comment Share on other sites More sharing options...
jl5501 Posted January 24, 2010 Share Posted January 24, 2010 yes ok , but after the if statement it should contain the 'ref' value, not before Quote Link to comment Share on other sites More sharing options...
MadTechie Posted January 24, 2010 Share Posted January 24, 2010 okay lets go back to basics what do you get from this ? if ($_GET['ref'] >= 1){ $insert['ref'] = $_GET['ref']; } echo $insert['ref']; print_r($_GET); better still try this if (!empty($_GET['ref']) && $_GET['ref'] >= 1){ $insert['ref'] = $_GET['ref']; } echo $insert['ref']; print_r($_GET); Quote Link to comment Share on other sites More sharing options...
seany123 Posted January 24, 2010 Author Share Posted January 24, 2010 okay so i placed it inside the if statement after the $insert[ref] and it showed the exact same print: Array ( [username] => sean2 [name] => sean2 [password] => md5 password => ss2@mafiakiller.com [registered] => 1264375687 [last_active] => 1264375687 [ip] => 94.2.58.23 ) Quote Link to comment Share on other sites More sharing options...
seany123 Posted January 24, 2010 Author Share Posted January 24, 2010 okay lets go back to basics what do you get from this ? if ($_GET['ref'] >= 1){ $insert['ref'] = $_GET['ref']; } echo $insert['ref']; print_r($_GET); better still try this if (!empty($_GET['ref']) && $_GET['ref'] >= 1){ $insert['ref'] = $_GET['ref']; } echo $insert['ref']; print_r($_GET); i tried the second one you gave and it showed this: Array ( ) Quote Link to comment Share on other sites More sharing options...
MadTechie Posted January 24, 2010 Share Posted January 24, 2010 i tried the second one you gave and it showed this: Array ( ) You didn't pass anything in the URL.. add ?ref=10 to it! Quote Link to comment Share on other sites More sharing options...
seany123 Posted January 24, 2010 Author Share Posted January 24, 2010 i tried the second one you gave and it showed this: Array ( ) You didn't pass anything in the URL.. add ?ref=10 to it! yeah i did i set ?ref=5 Quote Link to comment Share on other sites More sharing options...
MadTechie Posted January 25, 2010 Share Posted January 25, 2010 I don't think you did, but the code is correct, so your doing something wrong or if everything else is correct then i guess reinstall PHP and apache! Quote Link to comment Share on other sites More sharing options...
seany123 Posted January 25, 2010 Author Share Posted January 25, 2010 im using a live host... and php otherwise works fine.. this is the entire page: <?php ob_start(); /*******************************************/ /* Development / Maintanence /* by Seany123 /* for /* [REMOVED URL] /*******************************************/ include("lib.php"); define("PAGENAME", "Register"); include("templates/header.php"); srand((double)microtime()*1000000); //sets random seed $string = md5(rand(0,1000000)); $msg1 = "<font color=\"red\">"; //Username error? $msg2 = "<font color=\"red\">"; //Password error? $msg3 = "<font color=\"red\">"; //Verify Password error? $msg4 = "<font color=\"red\">"; //Email error? $msg5 = "<font color=\"red\">"; //Verify Email error? $error = 0; $ip = $_SERVER['REMOTE_ADDR']; if ($_POST['register']) { $username = ($_POST['username']); $password = md5($_POST['password']); //Check if ip has already been used $query = $db->execute("select `ip` from `players` where `ip`=?", array($ip)); if ($query->recordcount() > 0) { echo "Sorry, but you can't sign up because the IP address you are using is already being used on another account!"; echo "<br><br><a href=\"index.php\">[back]</a></table></div></div>"; //Include ADVERT PAGE include ("advert.php"); echo "</div>"; exit; } //Check if username has already been used $query = $db->execute("select `id` from `players` where `username`=?", array($_POST['username'])); //Check username if (!$_POST['username']) { //If username isn't filled in... $msg1 .= "You need to fill in your username!<br />\n"; //Add to error message $error = 1; //Set error check } else if (strlen($_POST['username']) < 3) { //If username is too short... $msg1 .= "Your username must be longer than 3 characters!<br />\n"; //Add to error message $error = 1; //Set error check } else if (!preg_match("/^[-_a-zA-Z0-9]+$/", $_POST['username'])) { //If username contains illegal characters... $msg1 .= "Your username may contain only alphanumerical characters!<br />\n"; //Add to error message $error = 1; //Set error check } else if ($query->recordcount() > 0) { $msg1 .= "That username has already been used. Please create only one account, Creating more than one account will get all your accounts Banned!<br />\n"; $error = 1; //Set error check } //Check password if (!$_POST['password']) { //If password isn't filled in... $msg2 .= "You need to fill in your password!<br />\n"; //Add to error message $error = 1; //Set error check } else if ($_POST['password'] != $_POST['password2']) { $msg3 .= "You didn't type in both passwords correctly!<br />\n"; $error = 1; } else if (strlen($_POST['password']) < 3) { //If password is too short... $msg2 .= "Your password must be longer than 3 characters!!<br />\n"; //Add to error message $error = 1; //Set error check } else if (!preg_match("/^[-_a-zA-Z0-9]+$/", $_POST['password'])) { //If password contains illegal characters... $msg2 .= "Your password may contain only alphanumerical characters!<br />\n"; //Add to error message $error = 1; //Set error check } //Check email if (!$_POST['email']) { //If email address isn't filled in... $msg4 .= "You need to fill in your email!<br />\n"; //Add to error message $error = 1; //Set error check } else if ($_POST['email'] != $_POST['email2']) { $msg5 .= "You didn't type in both email address correctly!"; $error = 1; } else if (strlen($_POST['email']) < 3) { //If email is too short... $msg4 .= "Your email must be longer than 3 characters!<br />\n"; //Add to error message $error = 1; //Set error check } else if (!preg_match("/^[-!#$%&\'*+\\.\/0-9=?A-Z^_`{|}~]+@([-0-9A-Z]+\.)+([0-9A-Z]){2,4}$/i", $_POST['email'])) { $msg4 .= "Your email format is wrong!<br />\n"; //Add to error message $error = 1; //Set error check } else { //Check if email has already been used $query = $db->execute("select `id` from `players` where `email`=?", array($_POST['email'])); if ($query->recordcount() > 0) { $msg4 .= "That email has already been used. Please create only one account, Creating more than one account will get all your accounts banned!<br />\n"; $error = 1; //Set error check } } if ($error == 0) { $insert['username'] = $_POST['username']; $insert['name'] = $_POST['username']; $insert['password'] = $password; $insert['email'] = $_POST['email']; $insert['registered'] = time(); $insert['last_active'] = time(); $insert['ip'] = $_SERVER['REMOTE_ADDR']; if (!empty($_GET['ref']) && $_GET['ref'] >= 1){ $insert['ref'] = $_GET['ref']; } echo $insert['ref']; print_r($_GET); $insert['validkey'] = $string; $query = $db->autoexecute('players', $insert, 'INSERT'); if (!$query) { $could_not_register = "Sorry, you could not register! Please contact the admin!<br /><br />"; } else { $insertid = $db->Insert_ID(); $email=$_POST['email']; $thekey=$string; $user = $_POST['username']; $pass = $_POST['password']; $subject = '[REMOVED URL] Activation!'; $message = "Thank you for registering at [REMOVED URL], please activate your account at: http://[REMOVED URL]/validate.php?email=$email&string=$string You can login to the game after activating account at: http://www.[REMOVED URL] with the following details: Username: $user password: $pass Best Regards [REMOVED URL] Admin Team."; $headers = "From: admin@[REMOVED URL]\r\nReply-To: admin@[REMOVED URL]"; mail($_POST['email'], $subject, $message, $headers); echo "Congratulations! You have successfully registered!<br />You will recieve an email to activate account."; echo "<br><br><a href=\"index.php\">[back]</a>"; //Include ADVERT PAGE include ("advert.php"); echo "</div>"; exit; } } } $msg1 .= "</font>"; //Username error? $msg2 .= "</font>"; //Password error? $msg3 .= "</font>"; //Verify Password error? $msg4 .= "</font>"; //Email error? $msg5 .= "</font>"; //Verify Email error? $msg6 .= "</font>"; //Verify IP error? ?> <?=$could_not_register?> <html> <head> <title>[REMOVED URL]</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link rel="stylesheet" href="/css/style.css" type="text/css" media="all" /> </head> <body alink="#cc9900" vlink="#cc9900" link="#cc9900"> <div id="left_c"> <div class="g_content"><h3 style="text-align: left"> [REMOVED URL]</h3><div class="g_text"> <table width='100%'> Welcome to [REMOVED URL], A new Mafia based game. Your role in [REMOVED URL] is simple, become the best! whether its being the top leveled mobster, Gang leader, Mugger or Exp Bunny. <br> <b>FEATURES INCLUDE:</b> <br> * Unique Mugging system. <br> * Unique Battle System. <br> * varitiy of different Houses. <br> * 20+ Different Crimes. <br> * 27 different Cities. <br> * Create Your own Gang. </table></div></div> <div class="g_content"><h3 style="text-align: left"> Attention</h3><div class="g_text"> <table width='100%'> Unfortunatly [REMOVED URL] is not supported by Internet Explorer. <br> Please use one of the following to play [REMOVED URL]: <br> <a href=\"http://www.google.com/chrome\">* Google Chrome</a> <br> <a href=\"http://www.mozilla.com/firefox\">* Mozilla FireFox</a> <br> </table></div></div> <div class="g_content"><h3 style="text-align: left"> Register</h3><div class="g_text"><table width='100%'> <form method="POST" action="register.php"> <table width="100%"> <tr><td width="40%"><b>Username</b>:</td><td><input type="text" name="username" value="<?=$_POST['username'];?>" /></td></tr> <td colspan="2"><?=$msg1;?></td> <tr><td width="40%"><b>Password</b>:</td><td><input type="password" name="password" value="<?=$_POST['password'];?>" /></td></tr> <td colspan="2"><?=$msg2;?></td> <tr><td width="40%"><b>Verify Password</b>:</td><td><input type="password" name="password2" value="<?=$_POST['password2'];?>" /></td></tr> <td colspan="2"><?=$msg3;?></td> <tr><td width="40%"><b>Email</b>:</td><td><input type="text" name="email" value="<?=$_POST['email'];?>" /></td></tr> <td colspan="2"><?=$msg4;?></td> <tr><td width="40%"><b>Verify Email</b>:</td><td><input type="text" name="email2" value="<?=$_POST['email2'];?>" /></td></tr> <td colspan="2"><?=$msg5;?></td> <br> <tr><td colspan="2"> By signing up, you agree that you have read and accept the <a href="tos.php">Terms of Service</a>.<br> <tr> <td> </td> <td> <input type="submit" name="register" value="Register!"></td></tr> </table> </form> </div> </div> <?php //Include ADVERT PAGE include ("advert.php"); ?> </div> </html> [code] maybe i have done something wrong. Quote Link to comment Share on other sites More sharing options...
MadTechie Posted January 25, 2010 Share Posted January 25, 2010 As i said, You didn't pass anything in the URL.. add ?ref=10 to it! for that form to process you need to POST the form BUT the form is NOT passing the get <form method="POST" action="register.php"> for example try <form method="POST" action="register.php?ref=10"> Quote Link to comment 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.