Aqua-Soft Forums: Php Sql Help - Aqua-Soft Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Php Sql Help Rate Topic: -----

#1 User is offline   ziptrx Icon

  • Group: Member
  • Posts: 64
  • Joined: 24-April 05

Posted 09 July 2010 - 02:06 AM

I was given a script, that needed some modification made to it, and I am in need of some assistance. I am having difficulties inserting some data into a table in the database. I am also hoping someone could clarify some of the code for me. Here is the code for the sign up page, and although it is broken with code tags, the code is all in order.
<?
	session_start();
	$page="signup";
	include"header.php";
	include"mysql.php";
	include"config.php";
	print"
		<h2>Creating an account</h2>
		<p class=\"post-by\">on $sitename</p>
	";

	if($_SESSION['loggedin']==1)
		{
			print"<center>You are already signed up, and logged in.</center>";
		}
	else
		{
			if($_POST['username'])
		{
	if($_POST['promo'] == "Your Promo Code Here")
		{
			$sm+=100;
		}

	$referal=$_POST['ref'];
	$username=$_POST['username'];
	$email=$_POST['email'];
	$paypal=$_POST['paypal'];

$username=str_replace(array("<", ">"), array("&lt;", "&gt;"), $username);
	$email=str_replace(array("<", ">"), array("&lt;", "&gt;"), $email);
	$paypal=str_replace(array("<", ">"), array("&lt;", "&gt;"), $paypal);
	$referal=str_replace(array("<", ">"), array("&lt;", "&gt;"), $referal);
	$q=mysql_query("SELECT * FROM users WHERE username='{$username}'",$c);

What does the above section do exactly?

if(mysql_num_rows($q))
		{
			die("<center>Username already in use.</br>Choose another.</center>");
		}
	if('{$username}' == '$referal')
		{
			die("<center>You cannot refer yourself.</center>");
		}
	else if($_POST['password'] != $_POST['cpassword'])
		{
			die("<center>Your passwords did not match.</br>Please go back and try again.</center>");
		}
	else
		{
			$_POST['ref'] = abs((int) $_POST['ref']);
			$ip = ($_SERVER['HTTP_X_FORWARDED_FOR'])
    			?  $_SERVER['HTTP_X_FORWARDED_FOR']
    			:  $_SERVER['REMOTE_ADDR'];
			$q=mysql_query("SELECT * FROM users WHERE userIP='$ip' OR signupIP='$ip'",$c);

				if(mysql_num_rows($q))
					{
						die("<center>You are not allowed to create more than one account per IP address.</center></br>
	 						<center> If you are using a proxy please disable it and try again.</center></br>
	 						<center>We apologize for the inconvenience.</center>");
					}

				if(isset($_POST['ref']))
					{
						$q=mysql_query("SELECT * FROM users WHERE `username`='$referal'",$c);
						$r=mysql_fetch_array($q);
						$f=mysql_query("SELECT * FROM users WHERE `username`='$referal'",$c);

$gangs=mysql_num_rows($f);

Does the above even serve a purpose? Reason I ask, is I can not find $gangs being used anywhere.

if(mysql_num_rows($q)==0)
							{
								$referal="";
							}
						if(mysql_num_rows($f)!=0)
							{
								$tref=mysql_query("SELECT * FROM users WHERE `username`='$referal'",$c);
								$theref=mysql_fetch_array($tref);
								mysql_query("UPDATE users SET referrals=referrals+1, current_balance=current_balance+$refbonus, total_earned=total_earned+.50 WHERE id='{$theref['id']}'",$c);
							}
					}

	$time=time();
			$emailcheck=md5(rand(100000,999999));
			$password=md5($_POST['password']);
			mysql_query("INSERT INTO users VALUES ('','{$username}','$password','0','{$email}','$emailcheck','','{$paypal}','','$ip','$ip','$time','$signupbonus','$signupbonus','0','0','$referal','');",$c) or die(mysql_error());

I know the above section is for inserting the data into the USERS table. I am trying to get $referal to also be inserted into the REFERRERS table, which has the following field; username.
$i=mysql_insert_id($c);

What does the above do? I can not find $i being used anywhere.


mail( $email, "Account Registered on $sitename",
<remove email part to shorten post>
print"
	<br><br><br><center>Your account has been successfully created.<br>Thank you for joining $sitename<br><br>
&gt; <a href=\"index.php\">Back To $sitename</a></center>
	";
}
}
else
{
print"
	<center>
	<form action=\"signup.php\" method=\"post\">
	<i>Username</i><br><input type=\"text\" name=\"username\"><br>
	<i>E-Mail</i><br><input type=\"text\" name=\"email\"><br>
	<i>Password</i><br><input type=\"password\" name=\"password\"><br>
	<i>Confirm Password</i><br><input type=\"password\" name=\"cpassword\"><br>
	<i>Paypal Email</i><br><input type=\"text\" name=\"paypal\"><br>
	<i>Referrer</i>: $ref<input type=\"hidden\" name=\"ref\" value=\"$ref\"><br><br>
	<input type=\"submit\" class=\"button\" value=\"Sign Up\"></form><br />
	</center>
";
}
}
include"side.php";
include"footer.php";
?>


The purpose for entering the users.referrer to referrer.username is there will be a script that when a member completes a project, his/her referrer will be given a credit. I figure that I would need the referrer table, for this, or could is possible to do a users.referrer = users.username? I could be wrong on all this...

Thanks in advance for any help. If any additional info is needed, please let me know.

Attached File(s)


This post has been edited by ziptrx: 09 July 2010 - 02:08 AM

0

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users