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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.