This topic is locked

Updating field in another table 4.2

10/13/2008 12:41:54 PM
PHPRunner Tips and Tricks
jimhnet author

I have an application where members are voting in an election of officers and I need to limit them to only being able to vote once. My members are in a table called registers with the key being set to r_id , it contains their username (uname) and password (passwd). The voting table contains the key (id) vote (vote) and relationship key (r_id). I set the master-detail relationship to registers (r_id) with the r_id in the vote table. I set a hard path to the add.php. My objective was to change the password to an arbitrary value when the person voted and them redirect them to a landing page.
In the add page I entered the following event code in the before record added event:
global $conn;

$strUpdate = "update registers set passwd=98765 where r_id=r_id";

db_exec($strUpdate,$conn);
and in the after record added did the redirection to the landing page.(Worked fine)

  1. When the first person voted it of course updated(which means it ignored my "where") all 3908 rows of the table instead of the one voting. I assumed that the conditional left side of the argument got the table from the "update registers" and the right side was always the working table.
  2. Exiting the application apparently leaves a login cookie set, which if the person voting reclicked the link could immediately vote again with no login required.
    Incidentally, I have five versions of this all stand alone in parallel directories for voting different work groups.
    Suggestions on a fix.
    Jim Freeman

T
thesofa 10/13/2008

OK, I wanted a quick vote from all the pupils at school on various different subjects, i did not want them to see the results of others votes, so each time they went to the list page they were redirected to the add page, where I did a check if record exists in the voting table, as each one voted, a record was stored in the voting table, called prom2007 in the code.

if the data exists, stick a message up .

here is the code

global $conn;

$strSQLExists = "select * from `prom2007` where PupID=".$_SESSION["id"];

$rsExists = db_query($strSQLExists,$conn);

$data=db_fetch_array($rsExists);

if($data)

{

echo "<h2><font color=red>This pupil has already voted.</font></h2>";

return false;

}

else

{

// if dont exist do something else

}
return true;
// return true if you like to proceed with adding new record

// return false in other case



the kids had to login with their normal network names and passwords, once they voted, that was it.

It worked well

This was the before add event on the add page too.
This might save a load of hard disc thrashing.
BTW, this should be in the other forum, not tips and tricks, maybe....
HTH