Page 1 of 1
adding +1 per email???
Posted: Sun Jun 20, 2010 1:47 pm
by s1rspyr0
Hey everyone. I'm working on a website and i'm trying to do something, but don't know if it can be done. I want my users to accumulate points based on referring new users. I've set up the register.php page to record the usual name, password, email address and have added a "reference" option for users to enter an email address of the user that referred them. everything records to the user database correctly. now here's to my question.
I've added another "numeric" column called "reference_points". Is there any code i could use that when a new user is registering, the "reference" column does a search against the "email" column and adds 1 point to the "reference_points" column for the user who's "email" matched the "reference" that the new user entered, and also gave an error message(which isn't nearly as important) if the email address put as a reference didn't exist?
Is this making any since? I've been using php for a long time, but never custom code, always altering templates to fit my needs. So i've learned just enough to be dangerous, as they say.
if it helps at all, here's the link to the register page:
http://www.gamerz-haven.net/register.php
also adding this to Database, it's kind of both...
Re: adding +1 per email???
Posted: Sun Jun 20, 2010 2:06 pm
by requinix
Uh...
Code: Select all
UPDATE table SET reference_points = reference_points + 1 WHERE email = "..."
Code: Select all
if (mysql_affected_rows() == 1) {
// okay
} else {
// no such email
}
Re: adding +1 per email???
Posted: Sun Jun 20, 2010 2:30 pm
by s1rspyr0
ok i feel like an idiot, but i can't make it work. i tried just how you had it, and am getting a parse error, so i tried it differently and the error is the same
Code: Select all
<?php
$conn = @mysql_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PASS) or die(mysql_error());
mysql_select_db(MYSQL_BASE_LS, $conn) or die(mysql_error());
$sql = "SELECT reference,
reference_points,
email,
FROM ".MYSQL_BASE_LS.".account_data,";
$sql = UPDATE TABLE SET "reference_points" = "reference_points" + 1 WHERE email = LG_REFERENCE;
if (mysql_affected_rows() == 1) {
// okay
} else {
// no such email
}
?>
Re: adding +1 per email???
Posted: Sun Jun 20, 2010 3:03 pm
by requinix
Looks like you need a
tutorial.
Re: adding +1 per email???
Posted: Sun Jun 20, 2010 3:57 pm
by s1rspyr0
ok the tutorial worked well to get rid of the errors, but it still doesn't work....
Code: Select all
<tr>
<td height="30" align="right"><strong><?php echo LG_REFERENCE;?>:</strong></td>
<td height="30"> <input name="reference" id="reference" type="text" class="inputs" style="width:100px;" maxlength="65" />
</td>
</tr>
</form>
</table>
<?php
@mysql_select_db(MYSQL_BASE_LS) or die( "Unable to select database");
mysql_query($query);
$ud_ref=$_POST['reference'];
$query = "UPDATE account_data SET $ud_ref = 'reference_points' + 1 WHERE email = reference";
if (mysql_affected_rows() == 1) {
// okay
} else {
// no such email
}
?>
i feel like a real moron here...
Re: adding +1 per email???
Posted: Sun Jun 20, 2010 4:24 pm
by s1rspyr0
ok im getting closer...
Code: Select all
<?php
@mysql_select_db(MYSQL_BASE_LS) or die( "Unable to select database");
mysql_query($query);
$query = "UPDATE account_data SET reference_points = reference_points + 1 WHERE email = reference";
if (mysql_affected_rows() == 1) {
// okay
} else {
// no such email
}
?>
my problem is "WHERE email = blah blah blah
i can't figure out how to make it equal whatever it is that users put in that input box.
the box is...
Code: Select all
<tr>
<td height="30" align="right"><strong><?php echo LG_REFERENCE;?>:</strong></td>
<td height="30"> <input name="reference" id="reference" type="text" class="inputs" style="width:100px;" maxlength="65" />
</td>
</tr>
Re: adding +1 per email???
Posted: Mon Jun 21, 2010 4:55 pm
by s1rspyr0
Code: Select all
if (isset($_POST['reference'])) {
@mysql_select_db(MYSQL_BASE_LS) or die( "Unable to select database");
$reference=$_POST['reference'];
$query = "UPDATE account_data SET reference_points=reference_points+1
WHERE email='" . mysql_real_escape_string($reference) . "'";
$result=mysql_query($query);
if (mysql_affected_rows() == 1) {
// okay
} else {
// no such email
}
}
works now