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

potential-code.txt

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

header('Content-Type: application/json');

$sql "SELECT 
    m.matchid, 
    m.player1id, 
    m.player2id, 
    m.isactive,
    u1.userid AS p1id, 
    u1.username AS player1name,
    u2.userid AS p2id, 
    u2.username AS player2name
FROM matches AS m
INNER JOIN rpsusers AS u1 ON m.player1id = u1.userid
INNER JOIN rpsusers AS u2 ON m.player2id = u2.userid"
;

$stmt $dbconn->prepare($sql);
$stmt->execute();

$matches = [];

while (
$res $stmt->fetch(PDO::FETCH_ASSOC)) {
    if (
$res['player1id'] && $res['player2id'] && $res['isactive'] == 1) {
        
$matches[] = $res;
    }
}

echo 
json_encode($matches);


html page below


<div id="betting-area"></div>

<
script>
async function loadBettingMatches() {
    try {
        const 
response await fetch('getmatchesbetting.php');
        const 
matches await response.json();
        const 
container document.getElementById('betting-area');
        
container.innerHTML ""// Clear previous content

        
matches.forEach(match => {
            const 
form document.createElement('form');
            
form.method 'POST';
            
form.innerHTML = `
                <strong>
${match.player1name} vs ${match.player2name}</strong><br>
                <label>
                    <input type="radio" name="chosenplayer" value="
${match.player1id}">
                    
${match.player1name}
                </label><br>
                <label>
                    <input type="radio" name="chosenplayer" value="
${match.player2id}">
                    
${match.player2name}
                </label><br>
                <input type="text" name="betamount" placeholder="Enter bet amount"><br>
                <input type="hidden" name="matchid" value="
${match.matchid}">
                <button type="submit">Place Bet</button>
                <hr>
            
`;
            
container.appendChild(form);
        });
    } catch (
err) {
        
console.error("Error fetching matches:"err);
    }
}

// Call it once, or use setInterval for updates
loadBettingMatches();
// Optional: update every 30 seconds
// setInterval(loadBettingMatches, 30000);
</script>