Arkanto5 Posted August 23, 2011 Share Posted August 23, 2011 Hello I'm making a website for our football team, and we have a page with certain statistics. The idea is that our coach can update the statistics via a certain page, where all the team members are listed. He then just have to click on a + or - when for example a player has scored a goal or has been booked. Now, to list the players, I have the following code: <table> <tr><td>Speler</td><td>Aanwezig</td></tr> <?php $query="select * from contacts ORDER BY familienaam"; $rt=mysql_query($query); echo mysql_error(); while($nt=mysql_fetch_array($rt)){ $nr=$nt[id]; echo " <tr> <td>$nt[familienaam]</td> <td>[color=green]$test [/color] <form action=\"aanwezigpluseen.php\" method=\"post\"> <input type=\"submit\" id=\"aanwezigpluseen\" value=\"+\"> </form> <input type=\"button\" id=\"aanwezigmineen\" value=\"-\"></td></tr>"; } ?> </table> and the page aanwezigpluseen.php consist of the following: <?php $con = mysql_connect("localhost","#######","#######"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("db_online_be", $con); $query="select * from contacts ORDER BY familienaam"; $rt=mysql_query($query); $sql="UPDATE contacts SET aanwezig=aanwezig+1 WHERE id=[b]$nr[/b]"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } include('admin.php'); ?> Now, the problem is with the part in bold... When I just write a number (8, for example), then the user with ID 8 gets an extra point added, and the coach gets redirected to the same page to add another one if necessary. In the first part of my codes, the part in green shows the correct user ID. THAT user ID must be used in my second code part, as in WHERE id= (the user id...). Any help? I hope that my problem is a bit clear with this description! Thanks in advance for your help! Link to comment https://forums.phpfreaks.com/topic/245507-updating-mysql-tables-with-a-userid/ Share on other sites More sharing options...
xyph Posted August 23, 2011 Share Posted August 23, 2011 Why not use a URL instead of a button? <a href="aanwezigpluseen.php?id=1&type=add">+</a> Then you can access these values using $_GET['id'] and $_GET['type'] Link to comment https://forums.phpfreaks.com/topic/245507-updating-mysql-tables-with-a-userid/#findComment-1260984 Share on other sites More sharing options...
Arkanto5 Posted August 24, 2011 Author Share Posted August 24, 2011 Good idea! I never thought of using a link instead of a button... It works like a charm now! Thank you very much ! Link to comment https://forums.phpfreaks.com/topic/245507-updating-mysql-tables-with-a-userid/#findComment-1261296 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.