Jump to content

Updating MySQL tables with a userID


Arkanto5

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.