hi , i am new to programming ,in fact i am learning it simply to create a platform for the donation movement i am launching.
my problem here is that i have different databases for the different events on the website to be exact there are databases for the user acounts info and also for every different kind of events. so from here i created a script for a donation event which require me to collect the 1000 first ordered username rows in this event database,
to then use those username to select the "winners" and update their user balance in the account info database.
i think first i would like to know if it is possible to do so and second i really need to know if i did wrong all the way .. my head hurt . and everytime i write a question on stackoverflow they downvote it and delete it so i deleted my account and here i am. i hope to find some answers. thank you in advance if you take the time to help me.
<?php
include countdown-timer.php
$DONATIONCLASHTIME = true;
session_start();
// If the user is not logged in redirect to the login page...//
if (!isset($_SESSION['loggedin'])) {
header('Location: index.html');
exit;
}
if ($DONATIONCLASHTIME > 0) {
$donationclash = true;
}
elseif ($donationclash = false) {
echo 'sorry the donation clash is not avilable at this moment';
}
$DATABASE_HOST = 'localhost';
$DATABASE_USER = 'root';
$DATABASE_PASS = '';
$DATABASE_NAME = '';
$con = mysqli_connect($DATABASE_HOST, $DATABASE_USER, $DATABASE_PASS, $DATABASE_NAME);
if (mysqli_connect_errno()) {
// If there is an error with the connection, stop the script and display the error.//
exit('Failed to connect to MySQL: ' . mysqli_connect_error());
}
if (isset($_POST['participation'] and $donationclash = true)) {
$_POST['participation'] = $donationamountinpending;
}
if ($stmt = $con->prepare("SELECT participationid, FROM donationclashdetails WHERE usernames, totaldonated = $_SESSION['name'], ?")) {
$stmt->bind_param('isi', $_SESSION['id'], $_SESSION['name'], $_POST['participation']);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($participationid, $usernames, $totaldonated,);
$stmt->fetch();
$stmt->close();
}
?>
<?php
$DATABASE_HOST = 'localhost';
$DATABASE_USER = 'root';
$DATABASE_PASS = '';
$DATABASE_NAME = '';
$con = mysqli_connect($DATABASE_HOST, $DATABASE_USER, $DATABASE_PASS, $DATABASE_NAME);
if (mysqli_connect_errno()) {
exit('Failed to connect to MySQL: ' . mysqli_connect_error());
}
if ($stmt = $con->prepare("SELECT userbalance, totaleventjoined, userlevel, userexperience, totaldonationdc, totalpifcoingained FROM accounts WHERE username = $_SESSION['name']")) {
// In this case we can use the account ID to get the account info.
$stmt->bind_param('i', $_SESSION['id']);
$stmt->execute();
$stmt->bind_result($userbalance, $totaleventjoined, $userlevel, $userexperience, $totaldonationdc, $totalpifcoingained);
$stmt->fetch();
$stmt->close();
}
if ($userbalance < $donationamountinpending) {
echo "<p>sorry you dont have enough Pifcoin to donate this amount<br>you can buy more by visiting the <a href='shoppingcart.php'>shop.</a></p>";
echo $donationamountinpending, echo $userbalance;
}
else if ($userbalance >= $donationamountinpending) {
$usernames = $_SESSION['name'];
$donationamountinpending = $donationamount;
$userbalance = $userbalance - $donationamount;
$totaldonationdc = $totaldonationdc + $donationamount;
$userexperience = $userexperience + $donationamout;
$userlevel = $userlevel + ($userexperience + 100) / 10;
$totaleventjoined = $totaleventjoined++;
echo "you successfully participated to the Donation clash.<br>You can keep track of how much you donated for the week in your profile.";
echo "or go take a look at the donation ranking page.";
}
if (!isset($donationamount <= 0)) {
$totalpifcoincollected = $totalpifcoincollected + $donationamount;
$totaldonated = $totaldonated + $donationamount;
}
mysqli_select_db($con, 'donationclash');
//this will be to do a ranking of the donations//
$sql = 'SELECT usernames, FROM donationclashdetails ORDER BY totaldonated DESC';
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
echo ' - ' . $row['usernames'] . $row['totaldonated'] . ' - ' .'<br>';
}
} else {
echo 'No records found!';
}
$con->close();
if ($donationclash = false) {
$donationclashcompleted = true;
echo 'The donation clash of this week is now completed'
}
mysqli_select_db($con, 'donationclash');
$sql = 'SELECT sum(totalpifcoincollected), FROM donationclashdetails ';
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_assoc($result)) {
echo "the total collected this week for the donation clash:"$row['totalpifcoincollected'];
}
$con->close();
}
mysqli_select_db($con, 'donationclash');
//this is for selecting the 1000 winners of the week//
$sql = 'SELECT usernames, totaldonated, FROM donationclashdetails LIMIT(1000) ORDER BY totaldonated DESC';
$result = mysqli_query($con, $sql);
if (mysqli_num_rows($result) > 0) {
while($winnerrow = mysqli_fetch_assoc($result)) {
echo ' - ' . $winnerrow['usernames'] . $winnerrow['totaldonated'] . ' - ' .'<br>';
}
}
if ($donationclashcompleted = true) {
/*here i retain 35% of the donations of the week in order to
distribute it between multiple voted foundations during the week*/
$prizeamount = ($winnerrow['totaldonated'] -35%) / 1000;
$winners = $winnerrow['usernames'];
}
if isset($winners) {
/* !!! i am lost !! also it could all be errors everywhere since it is mostly a theorical script not the finish product at all.
if you have any advices , feel free to share your opinion.. and no i didnt test anything in this code i was so scared that it breaks my pc.. yet it was all from head but i am curious to see at wich point i was wrong. */
}
else {
echo 'No records found!';
}
?>