Webbserverprogrammering 1

Show sourcecode

The following files exists in this folder. Click to view.

webbsrvprg/projects/

bacon-egg-pizza.php
cquiz.php
create-account.php
create-account111.php
create-quiz.php
create-quiz2.php
createaccount.php
delete-quiz.php
drop-rps-tables.php
legacy-code-rps.php
legacy-index.php
login.php
logincheck.php
newpassword-verify.php
newpassword.php
potential-code.txt
quiz-db-init.php
quizhub.php
quizhub2.php
results.php
rpsaccount-ajax-user-search.php
rpsaccount.php
rpsbetting-ajax-match-finder.php
rpsbetting.php
rpsbettingleaderboard.php
rpschangepassword.php
rpschangepassword.txt
rpsgame-ajax.php
rpsgame.php
rpsgameresults.php
rpshostnewgame.php
rpshub.php
rpsleaderboard.php
rpslib.php
rpslogin.php
rpsmaininclude.php
rpsproject/
rpsusersearch.php
table-init.php
verification.php

rpsbetting.php

50 lines ASCII Windows (CRLF)
<?php require('rpsmaininclude.php'); 

$sql "SELECT bettingpoints FROM rpsusers WHERE userid=?";
$stmt=$dbconn->prepare($sql);
$stmt->execute([$_SESSION['userid']]);

$_SESSION['currentBP']=0;

if(
$res=$stmt->fetch(PDO::FETCH_ASSOC)){
    
$_SESSION['currentBP']=$res['bettingpoints'];
}
else{
    
$_SESSION['currentBP']=0;
}

if(isset(
$_POST['chosenplayer']) AND isset($_POST['betamount']) AND $_POST['betamount']!="" AND isset($_POST['matchid'])){
    if(
$_SESSION['currentBP'] >= $_POST['betamount']){
        
//enter bet
        
$sql "INSERT INTO bets (matchid, userid, totalbet, beton) VALUES (?,?,?,?)";
        
$stmt=$dbconn->prepare($sql);
        
$stmt->execute([$_POST['matchid'],$_SESSION['userid'],$_POST['betamount'],$_POST['chosenplayer']]);
        
        
//remove bettingpoints
        
$sql="UPDATE rpsusers SET bettingpoints=? WHERE userid =?";
        
$stmt =$dbconn->prepare($sql);
        
$_SESSION['currentBP']=$_SESSION['currentBP']-$_POST['betamount'];
        
$stmt->execute([$_SESSION['currentBP'], $_SESSION['userid']]);
    }


}

//getMatchesBettingVersionV2($dbconn,$_SESSION['userid']);
?>
<html>
    <h1>Betting time! Double or nothing</h1>
    <?php echo "current amount: ".$_SESSION['currentBP'];?>
</html>

<div id="matchinfospace"></div>
<script>
    async function getMatchesStatusAjax(){
        let getmatchinfo = await fetch("rpsbetting-ajax-match-finder.php?userid=<?php echo $_SESSION['userid'];?>");
        let matchinfo = await getmatchinfo.text();
        document.getElementById('matchinfospace').innerHTML = matchinfo;
        //print(matchinfo);
    }
    //setInterval(getMatchesStatusAjax,1000)
    getMatchesStatusAjax();
</script>