I have a simple page/database setup where you can increment or decrement the point total for person A or person B.
I've gotten some help, throwing some things into their own function to clean things up. I'm new to php and mysql; reading over what I have I understand all the logic, I just can't figure out how to finish it off, in the sense that as it is now, any button will add a point; I need to get the Subtract point button working too.
My database is table 'user' with points and name within
Here's what I have:
<?php
function print_r_dump( $val )
{
echo '<pre>';
print_r( $val );
echo '</pre>';
}
//if ( isset( $_POST ) || isset( $_POST['Add point'] ) )
if ( isset( $_POST ) )
{
//Prints what's in post
print_r_dump( $_POST );
$str = "select * from user where name = '";
$str .= $_POST['person'];
$str .= "'";
$link = mysql_connect('mysql.xxxxx.net', 'xxxxx', 'xxxxx');
mysql_select_db('xxxxx_points', $link);
$result = mysql_query( $str , $link);
$row = mysql_fetch_assoc($result) ;
$points = $row['points'];
$str = 'update user set points = '. ($points+1) . ' where name = \''. $_POST['person'] . '\'';
$result = mysql_query( $str , $link);
}
$link = mysql_connect('mysql.xxxxx.net', 'xxxxx', 'xxxxx');
mysql_select_db('xxxxx_points', $link);
$str = "SELECT points FROM user WHERE name='Person A'" ;
$str = "SELECT * FROM user ";
$result = mysql_query( $str , $link);
$results = array();
while ( $row = mysql_fetch_assoc($result) )
{
$results[ $row['name'] ] = $row['points'];
}
?>
Person A's count: <?php echo $results['Person A']; ?>
<br>
<form method="post" action="index.php">
<input type="submit" name="submit_button" value="Add point" />
<input type="submit" name="submit_button" value="Subtract point" />
<input type="hidden" name="person" value="Person A" />
</form>
<br>
Person B's count: <?php echo $results['Person B']; ?>
<br>
<form method="post" action="index.php">
<input type="submit" name="submit_button" value="Add point" />
<input type="submit" name="submit_button" value="Subtract point" />
<input type="hidden" name="person" value="Person B" />
</form>
<?
print_r_dump( $results );
?>