s1rspyr0 Posted June 21, 2010 Share Posted June 21, 2010 hey everyone. i tried getting help at another forum, but was kinda run off because i'm still learning. so i'm going to try this one and see how it goes... 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 <form name="frm_cadastro" id="frm_cadastro" method="post" action="register.php"> <tr> <td width="42%" height="30" align="right"> <strong><?php echo LG_LOGIN;?>:</strong></td> <td width="58%" valign="top"> <input name="name" type="text" class="inputs" id="name" style="width:120px;" maxlength="45" /> </td> </tr> <tr> <td height="30" align="right"> <strong><?php echo LG_PASSWORD;?>:</strong></td> <td valign="top"> <input name="password2" type="password" class="inputs" id="password2" style="width:100px;" maxlength="65"/> </td> </tr> <tr> <td height="30" align="right"> <strong><?php echo LG_PASSWORD_CONFIRM;?>:</strong></td> <td valign="top"> <input name="password" type="password" class="inputs" id="password" style="width:100px;" maxlength="65"/> </td> </tr> <tr> <td height="30" align="right"><strong><?php echo LG_EMAIL;?>:</strong></td> <td height="30"> <input name="email" id="email" type="text" class="inputs" style="width:100px;" maxlength="65" /> </td> </tr> <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> <tr> <td height="30" align="right"><strong><?php echo LG_CAPTCHA;?>:</strong></td> <td height="30"> <input name="user_code" id="user_code" type="text" class="inputs" style="width:80px;" maxlength="5" /> </td> </tr> <tr> <td > </td> <td><img src="img_captcha.php" width="200" height="60" alt="" style="border: 1px solid #000000; padding: 2px;" /> </td> </tr> <tr> <td > </td> <td><input type="image" src="_images/bt_enviar.gif" width="46" height="14" border="0"></td> </tr> </form> </table> <?php @mysql_select_db(MYSQL_BASE_LS) or die( "Unable to select database"); mysql_query($query); $reference=$_POST['reference']; $query = "UPDATE TABLE SET reference_points=reference_points+1 WHERE email=$reference"; $result=mysql_query($query); if (mysql_affected_rows() == 1) { // okay } else { // no such email } ?> i have tried this sql thing every which way anyone can possibly image except the right way. The only thing in the form that really matters is the reference and email portion, the rest of the code was already programmed and works like it's supposed to. i can't seem to get the WHERE email= part to post in the right spot. i have the column on the sql table as text, have also tried numeric and decimal. any help at all would be most appreciated Link to comment https://forums.phpfreaks.com/topic/205375-updating-mysql-via-php-form/ Share on other sites More sharing options...
DavidAM Posted June 21, 2010 Share Posted June 21, 2010 if (isset($_POST['reference'])) { // #1 // #2 - Are you already connected ? @mysql_select_db(MYSQL_BASE_LS) or die( "Unable to select database"); // #3 - mysql_query($query); $reference=$_POST['reference']; $query = "UPDATE /* #4 TABLE */ SET reference_points=reference_points+1 WHERE email='" . mysql_real_escape_string($reference) . "'"; // #5 $result=mysql_query($query); if (mysql_affected_rows() == 1) { // okay } else { // no such email } } 1) You need to check that the page was posted before acting on the POSTed data. When the user first loads the page, before filling out any fields (and clicking the submit button), you do not want to update the database. 2) You do not have a database connection there; maybe it is elsewhere 3) You are executing a query that has not been defined 4) You need to specify the table name to be updated 5) You have to enclose the reference in quotes and you should really escape it. Link to comment https://forums.phpfreaks.com/topic/205375-updating-mysql-via-php-form/#findComment-1074820 Share on other sites More sharing options...
s1rspyr0 Posted June 21, 2010 Author Share Posted June 21, 2010 omg i love you.... the db connect was at the top of the page, i just didn't copy that far up, just the lil piece that wasn't working. thank you so much i can't begin to tell you how awesome that makes you... Link to comment https://forums.phpfreaks.com/topic/205375-updating-mysql-via-php-form/#findComment-1074822 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.