I'm still new to certain PHP functions. Is there any way I can clean up the following code, because I know all of this is just unnecessary, and it's giving me a headache. Everything after the if statement is the same for each set of code.
if($class == "2"){if ($posts >= 1){
$sql = "UPDATE users SET posts=posts+1,tposts=tposts+1,points=points+25,tpoints=tpoints+25 WHERE `users`.`friendid`='$friend'";
$insert = "INSERT INTO proofs ( `ID` ,`friendid` ,`bulletinid`)VALUES('', '$friend' , '$binfo');";
mysql_query($insert) or die(mysql_error());
if (!mysql_query($sql)) {die('Error: ' . mysql_error());} echo "";}
else {$sql = "UPDATE users SET posts=posts+1,tposts=tposts+1 WHERE `users`.`friendid` = '$friend'";
mysql_query($sql) or die(mysql_error());
$insert = "INSERT INTO proofs ( `ID` ,`friendid` ,`bulletinid`)VALUES('', '$friend' , '$binfo');";
mysql_query($insert) or die(mysql_error());}}
if($class == "3"){if ($posts >= 2){
$sql = "UPDATE users SET posts=posts+1,tposts=tposts+1,points=points+25,tpoints=tpoints+25 WHERE `users`.`friendid`='$friend'";
$insert = "INSERT INTO proofs ( `ID` ,`friendid` ,`bulletinid`)VALUES('', '$friend' , '$binfo');";
mysql_query($insert) or die(mysql_error());
if (!mysql_query($sql)) {die('Error: ' . mysql_error());} echo "";}
else {$sql = "UPDATE users SET posts=posts+1,tposts=tposts+1 WHERE `users`.`friendid` = '$friend'";
mysql_query($sql) or die(mysql_error());
$insert = "INSERT INTO proofs ( `ID` ,`friendid` ,`bulletinid`)VALUES('', '$friend' , '$binfo');";
mysql_query($insert) or die(mysql_error());}
if($class == "4"){if ($posts >= 3){
$sql = "UPDATE users SET posts=posts+1,tposts=tposts+1,points=points+25,tpoints=tpoints+25 WHERE `users`.`friendid`='$friend'";
$insert = "INSERT INTO proofs ( `ID` ,`friendid` ,`bulletinid`)VALUES('', '$friend' , '$binfo');";
mysql_query($insert) or die(mysql_error());
if (!mysql_query($sql)) {die('Error: ' . mysql_error());} echo "";}
else {$sql = "UPDATE users SET posts=posts+1,tposts=tposts+1 WHERE `users`.`friendid` = '$friend'";
mysql_query($sql) or die(mysql_error());
$insert = "INSERT INTO proofs ( `ID` ,`friendid` ,`bulletinid`)VALUES('', '$friend' , '$binfo');";
mysql_query($insert) or die(mysql_error());}}
if($class == "5"){if ($posts >= 4){
$sql = "UPDATE users SET posts=posts+1,tposts=tposts+1,points=points+25,tpoints=tpoints+25 WHERE `users`.`friendid`='$friend'";
$insert = "INSERT INTO proofs ( `ID` ,`friendid` ,`bulletinid`)VALUES('', '$friend' , '$binfo');";
mysql_query($insert) or die(mysql_error());
if (!mysql_query($sql)) {die('Error: ' . mysql_error());} echo "";}
else {$sql = "UPDATE users SET posts=posts+1,tposts=tposts+1 WHERE `users`.`friendid` = '$friend'";
mysql_query($sql) or die(mysql_error());
$insert = "INSERT INTO proofs ( `ID` ,`friendid` ,`bulletinid`)VALUES('', '$friend' , '$binfo');";
mysql_query($insert) or die(mysql_error());}}
if($class == "6"){if ($posts >= 5){
$sql = "UPDATE users SET posts=posts+1,tposts=tposts+1,points=points+25,tpoints=tpoints+25 WHERE `users`.`friendid`='$friend'";
$insert = "INSERT INTO proofs ( `ID` ,`friendid` ,`bulletinid`)VALUES('', '$friend' , '$binfo');";
mysql_query($insert) or die(mysql_error());
if (!mysql_query($sql)) {die('Error: ' . mysql_error());} echo "";}
else {$sql = "UPDATE users SET posts=posts+1,tposts=tposts+1 WHERE `users`.`friendid` = '$friend'";
mysql_query($sql) or die(mysql_error());
$insert = "INSERT INTO proofs ( `ID` ,`friendid` ,`bulletinid`)VALUES('', '$friend' , '$binfo');";
mysql_query($insert) or die(mysql_error());}}
if($class == "7"){if ($posts >= 6){
$sql = "UPDATE users SET posts=posts+1,tposts=tposts+1,points=points+25,tpoints=tpoints+25 WHERE `users`.`friendid`='$friend'";
$insert = "INSERT INTO proofs ( `ID` ,`friendid` ,`bulletinid`)VALUES('', '$friend' , '$binfo');";
mysql_query($insert) or die(mysql_error());
if (!mysql_query($sql)) {die('Error: ' . mysql_error());} echo "";}
else { $sql = "UPDATE users SET posts=posts+1,tposts=tposts+1 WHERE `users`.`friendid` = '$friend'";
mysql_query($sql) or die(mysql_error());
$insert = "INSERT INTO proofs ( `ID` ,`friendid` ,`bulletinid`)VALUES('', '$friend' , '$binfo');";
mysql_query($insert) or die(mysql_error()); }}}}}}