-
Posts
253 -
Joined
Everything posted by alexandre
-
ok so if i want the new users donation to be added to their totaldonated how should i proceed because if their previous donations has already been inserted in the database i do need to update it no ?
-
yes i saw that right now i am trying to figure a way to get the sum of multiple duplicate rows but for only one column to update the to this sum related to their participationid binded to their session id. here is what i am experimenting $stmt = $con->prepare('SELECT sum(totaldonated) FROM donationclashdetails WHERE participationid = ?'); $stmt->bind_param('i', $_SESSION['id']); $result2 = mysqli_query($con, $stmt); while ($result3 = mysqli_fetch_assoc($result2)) { $stmt = $con->prepare("UPDATE INTO donationclashdetails (totaldonated) VALUES (?) WHERE participationid = ?") { $stmt->bind_param('ii', $result3, $_SESSION['id']); $stmt->execute();
-
alright , thanks a lot for your help, i asked you a lot. and now i have a lot to do since you have unstuck my script haha, have a good night. i will come back maybe if i am really lost but i got lot to learn so i dont wanna bother you too much.
-
when you look at this error here : Fatal error: Uncaught ArgumentCountError: Number of bind variables doesn't match number of fields in prepared statement in C:\xampp\htdocs\container\donation-clash\donation-clash.php:64 Stack trace: #0 C:\xampp\htdocs\container\donation-clash\donation-clash.php(64): mysqli_stmt->bind_result(2, 'alexandre', '20') #1 {main} thrown in C:\xampp\htdocs\container\donation-clash\donation-clash.php on line 64 it is saying the the number of binded variables doesnt match the number of prepared in the query but if you look at the code you can clearly see there is the same amount .. this is what i do not understand .
-
for the bind_result around line 65 , when i remove the bind_result it gives me the error i will post below. just as if all the variables used below wasnt binded anymore so i would like to understand how comes this seems binded if they are not supposed to be. but i also removed the store_result which is not on the code above and the only way everything is staying binded is if i leave the bind_result there. and i understand about the pdo extension i just really liked the format even if it forces me to write more code, the effect that the words have on my understanding is better like that, but if you think i should definitely learn it for more efficiency i will do so also i have all the time until my last breath so this isnt much of a problem, i am actually looking at how validating forms data on both server and client side efficiently. Warning: Undefined variable $participationid in C:\xampp\htdocs\container\donation-clash\donation-clash.php on line 70 Warning: Undefined variable $participationid in C:\xampp\htdocs\container\donation-clash\donation-clash.php on line 83 Fatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'usernames, totaldonated FROM donationclashdetails ORDER BY totaldonated DESC' at line 1 in C:\xampp\htdocs\container\donation-clash\donation-clash.php:96 Stack trace: #0 C:\xampp\htdocs\container\donation-clash\donation-clash.php(96): mysqli_query(Object(mysqli), 'SELECT * userna...') #1 {main} thrown in C:\xampp\htdocs\container\donation-clash\donation-clash.php on line 96
-
just a little note there, the binding is actualy processed because if i remove the bind result it unbind my main variables which are linked till the bottom of the script. so participation id doesnt mean anything if i unbind and totaldonated neither, so i think logically the bind is actually binding the result which is what making the value that are added to the database taking the value of the session id as well as the session username. if i remove this nothing works.
-
yes i agree. i should have the informations needed to get this working i saved your advices up there this will be helpful. thank you
-
Fatal error: Uncaught ArgumentCountError: Number of bind variables doesn't match number of fields in prepared statement in C:\xampp\htdocs\container\donation-clash\donation-clash.php:63 Stack trace: #0 C:\xampp\htdocs\container\donation-clash\donation-clash.php(63): mysqli_stmt->bind_result(2, 'alexandre', '25') #1 {main} thrown in C:\xampp\htdocs\container\donation-clash\donation-clash.php on line 63 this is the only error appearing for me the llast time i tried
-
i updated the code a little bit since the code up there but not much, i am thinking about changing the setup around the session id related stuff and the actual event details binded to id as you said about the arrays i am trying to figure a setup but for now the code look like this. and this code right now is stopping working at the query or something , it is adding the desired values in the database but if you reload the page it keeps adding more rows and alsos i get a error saying that the number of binded variables doesnt match or something but the content still getting added to database <?php include 'countdown-timer.php'; include './includes/connect_db1.php'; $donationclash = $DONATIONCLASHTIME; // We need to use sessions, so you should always start sessions using the below code. session_start(); // If the user is not logged in redirect to the login page... if (!isset($_SESSION['loggedin'])) { header('Location: index.html'); exit; } if ($stmt = $con->prepare("SELECT userbalance, totaleventjoined, totalpifcoingained, totaldonationdc, userlevel, userexperience FROM accounts WHERE id = ?")) { // 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, $totalpifcoingained, $totaldonationdc, $userlevel, $userexperience); $stmt->fetch(); $stmt->close(); } else { echo 'connexion broken try again later'; } $userbalance = 200; echo $userbalance; if ($DONATIONCLASHTIME >= 1) { $donationclash = true; echo "<div class='formdc'><form action='#' method='post' enctype='multipart/form-data'> enter your amount:<input type='text' name='participation'> <div class='participation'><button type='submit' formenctype='text/plan' formmethod='POST'>submit participation</button></div></div>"; } else { $donationclash = false; echo 'sorry the donation clash is not avilable at this moment'; exit; } if (($_SERVER["REQUEST_METHOD"] == "POST") && $_POST['participation'] > 0 ) { $donationamountinpending = $_POST['participation']; } else { echo "the value entered must be a number of type integer example: 1,2,3,etc.."; exit; } if ($_POST['participation'] <= 0) { echo 'please enter an amount in order to participate example: 1,2,3,etc..'; exit; } if ($donationamountinpending > $userbalance) { echo 'sorry you do not have enough Pifcoin to participate'; echo $donationamountinpending; echo $userbalance; exit; } else if (($userbalance >= $donationamountinpending) && $donationclash == true){ $donationamount = $donationamountinpending; } if ($stmt = $con->prepare("REPLACE INTO donationclashdetails (participationid, usernames, totaldonated) VALUES ( ?, ?, ?)")) { // In this case we can use the account ID to get the account info. $stmt->bind_param('isi', $_SESSION['id'], $_SESSION['name'], $_POST['participation'],); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($_SESSION['id'], $_SESSION['name'], $_POST['participation']); } else { echo 'connexion broken retry later'; exit; } if (($participationid == $_SESSION['id']) && $totaldonated == 0) { $userbalance = $userbalance - $donationamount; $totaldonated = $donationamount; $totaldonationdc = $totaldonationdc + $donationamount; $userexperience = $userexperience + $donationamout; $userlevel = $userlevel + $userexperience / 10; $totalpifcoincollected = $donationamount; $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 clash ranking page."; } else if (isset($_POST['participation']) && $_SESSION['id'] == $participationid) { $userbalance = $userbalance - $donationamount; $totaldonated = $totaldonated + $donationamount; $totaldonationdc = $totaldonationdc + $donationamount; $userexperience = $userexperience + $donationamout; $userlevel = $userlevel + $userexperience +100 / 10; $totaleventjoined = $totaleventjoined++; $totalpifcoincollected = $totalpifcoincollected + $donationamount; 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 to see your updated rank."; } include './includes/connect_db1.php'; $sql= 'SELECT * usernames, totaldonated FROM donationclashdetails ORDER BY totaldonated DESC'; $result = mysqli_query($con, $sql); if (mysqli_num_rows($result) > 0) { while($row = mysqli_fetch_assoc($result)) { //rankings echo $row['participationid']. $row['usernames']. $row['totaldonated']. ' - ' . '<br>'; } } else { echo 'No records found!'; } $sql = 'SELECT sum(totalpifcoincollected) FROM donationclashdetails'; $result = mysqli_query($con, $sql); if (mysqli_num_rows($result) > 0) { while($row = mysqli_fetch_assoc($result)) { //displaying the total amount of pifcoin collected by participants for the week echo "the total collected this week for the donation clash:"; echo $row['totalpifcoincollected']; } } else { echo 'no records found!'; } if ($donationclash = false) { $donationclashcompleted = true; echo 'The donation clash of this week is now completed'; } else { //sinon we display rankings echo $row['participationid']. $row['usernames']. $row['totaldonated']. ' - ' . '<br>'; } //here we select the 1000 winners of the week $sql = 'SELECT * participationid, usernames, totaldonated FROM donationclashdetails LIMIT(1000) ORDER BY totaldonated DESC '; $result = mysqli_query($con, $sql); if (mysqli_num_rows($result) > 0) { while($row = mysqli_fetch_assoc($result)) { echo $row['participationid']. $row['usernames']. $row['totaldonated']. ' - ' .'<br>'; } } if ($donationclashcompleted = true) { $winnersparticipationid = $row['participationid']; $prizeamount = $row['totalpifcoincollected']; cal_percentage(65, $prizeamount); $prizeamount = $prizeamount / 1000; $winnersname = $row['usernames']; $winnersamount = $prizeamount; } if (isset($_POST['participation']) && $_SESSION['id'] == $winnersparticipationid) { $userbalance = $userbalance + $winnersamount; echo "<div class='winnersannouncement'>congratulation ". $_SESSION['name']. ", you just won:" . $winnersamount .'</div>'; } else if (!isset($_POST['participation']) && $_SESSION['id'] !== $winnersparticipationid) { echo "sorry i wish you a better luck next time, you are not a winner on this week"; exit; } while ($donationclashcompleted = true) { $winners = $winnersname.$winnersamount; echo $winners; break; } ?>
-
the code that you see there is a totally unfinished product .. it is what i got back from my file being wiped after a crash but i do understand all your questions and this will help me to fix it better. also i started coding php at the beginning of the week so i dont really expect to master the syntax already but i dont stop trying . thank you for taking the time to explain those. i would maybe have a question about the pdo database extension that you noted there . i read a lot about sql injection and it seem like you reduce the risk of such threat by using prepared queries. so i was thinking to only use those prepared queries if possible. or is there situations where i cant use those prepared queries ?
-
It’s ok , this is something I can simply google and this code still got many errors in it so I will simply fix it myself but thanks anyway for your help.
-
right now it is unfinished but heres what i got back and also the variables that i do not want to change are the ones binded or fetched to the session id related stuff <?php include 'countdown-timer.php'; $DONATIONCLASHTIME = true; $donationclash = true; // We need to use sessions, so you should always start sessions using the below code. session_start(); // If the user is not logged in redirect to the login page... if (!isset($_SESSION['loggedin'])) { header('Location: index.html'); exit; } require_once('./includes/connect_db1.php'); if ($stmt = $con->prepare("SELECT userbalance, totaleventjoined, totalpifcoingained, totaldonationdc, userlevel, userexperience FROM accounts WHERE id = ?")) { // 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, $totalpifcoingained, $totaldonationdc, $userlevel, $userexperience); $stmt->fetch(); $stmt->close(); } if ($DONATIONCLASHTIME > 0) { $donationclash = true; } else { $donationclash = false; echo 'sorry the donation clash is not avilable at this moment'; exit; } if ($_SERVER["REQUEST_METHOD"] == "POST") { $donationamountinpending = $_POST['participation']; } else if ($_POST['participation'] != 0) { echo 'please enter an amount in order to participate'; exit; } if ($donationamountinpending > $userbalance) { echo 'sorry you do not have enough Pifcoin to participate'; echo $donationamountinpending; echo $userbalance; exit; } else if ($userbalance >= $donationamountinpending and $donationclash = true){ $donationamount = $donationamountinpending; require_once('./includes/connect_db1.php'); } if ($stmt = $con->prepare("INSERT INTO donationclashdetails (participationid, usernames, totaldonated) VALUES ( ?, ?, ?)")) { // In this case we can use the account ID to get the account info. $stmt->bind_param('isi', $_SESSION['id'], $_SESSION['name'], $_POST['participation'],); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($_SESSION['id'], $_SESSION['name'], $_POST['participation']); } if ($stmt = $con->prepare("SELECT participationid, usernames, totaldonated, totalpifcoincollected FROM donationclashdetails WHERE participationid = ?")) { // 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($participationid, $usernames, $totaldonated, $totalpifcoincollected); $stmt->fetch(); $stmt->close(); } if ($participationid = $_SESSION['id'] and $totaldonated = 0) { $userbalance = $userbalance - $donationamount; $totaldonated = $donationamount; $totaldonationdc = $totaldonationdc + $donationamount; $userexperience = $userexperience + $donationamout; $userlevel = $userlevel + ($userexperience + 100) / 10; $totalpifcoincollected = $donationamount; $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."; } elseif (isset($_POST['participation']) && $_SESSION['id'] === $participationid) { $userbalance = $userbalance - $donationamount; $totaldonated = $totaldonated + $donationamount; $totaldonationdc = $totaldonationdc + $donationamount; $userexperience = $userexperience + $donationamout; $userlevel = $userlevel + ($userexperience + 100) / 10; $totaleventjoined = $totaleventjoined++; $totalpifcoincollected = $totalpifcoincollected + $donationamount; $totaldonated = $totaldonated + $donationamount; 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 to see your updated rank.;" } require_once('./includes/connect_db1.php'); mysqli_select_db($con, 'donationclash'); $sql = 'SELECT * usernames, totaldonated 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!'; } if ($donationclash = false) { $donationclashcompleted = true; echo 'The donation clash of this week is now completed'; } $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:"; echo $row['totalpifcoincollected']; } } //winners selected $sql = 'SELECT usernames, totaldonated FROM donationclashdetails LIMIT(1000) 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>'; $stmt->close(); } } if ($donationclashcompleted = true) { $prizeamount = $row['totalpifcoincollected']; cal_percentage(65, $prizeamount) $prizeamount = $prizeamount / 1000; $winnersname = $row['usernames']; $winnersamount = $prizeamount; } if ($donationclashcompleted = true) { print $winnersname; print $winnersamount; } else { echo 'there is no winners yet!'; } ?>
-
i have a question do this code changes the variables in which i fetched data higher in the script? $sql = 'SELECT usernames, totaldonated FROM donationclashdetails LIMIT(1000) 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>'; $stmt->close(); }
-
Nope I just found it hilarious to point to the fact of getting a good editor who is offering backups. And also I think what caused the wipe is that I had to force the shutdown of the laptop by holding power button.. laptop was going to 🤯
-
Dang for a second I had hope now my hope is gone the plain txt file is totally empty … it has been wiped for some reason.
-
Yup it is atom
-
i am lucky i had sent my code from like 5 hours ago to the admin here in message so i have a kind of backup but that still sucks ill see for the temp file. might be my last hope.
-
It’s a one file script that take the entered value of a post method and if conditions are met is stored and along with all other participants then if the 1000 highest donator at the end of the week gets something but the while loop that was unbroken was simply something I was trying to verify that the amount entered was higher than zero , I honestly have no idea how this have happened maybe because I have like 30 tab opened but still laptop just crashed and the only file wiped was the one active so it is weird
-
!!! I need help . I messed up forgetting to break a while loop and it crashed my pc and now my main file that was open and I was working on with the script in simply been completely erased now I can only see the number one of the first line in code editor and all the rest are dots pleeease tell me there is a way to recover It I had literally just finished it …. I wanna cry right now.
-
thank you i will definitely take a look at this cakePHP and yes it is the first php code i was ever writing or at least partially writing. i might have to continue learning i just found it hard to find a good php course that isnt deprecated. i think i followed at least 3 or 4 of them to end on something that wasnt working anymore and i couldnt find a way to go around this deprecations by myself so it got a bit complicated. its relatively easy to integrate premade features compared to making them from scratch. anyways thank you for your advices i will come back if i ever get better.
-
Should I add more of my files like the authenticate.php for register and login and everything maybe it would help , because I have my website done and registering and login working fine, I wanted to attack the most complicated of the features I wanted to add first. Let me know if you need to see more.
-
And for the total donated equal the session name is that I put usernames first and then total donated so the amount donated is unknow and set by the user and also bind the usernames to the session user names . Since the event have to list the usernames but those are in a different database with user account info and I didn’t really know how to do this yet.
-
Sadly I am working alone on this but I effectively don’t know a lot about syntax rules. honestly I was writing in my logic to form my idea first and was thinking to make the adjustments needed once I would know better but I think I must have messed everything around. You have to assume here that another file contain a label for participation amount and a submit button where the form uses post method, I don’t know if it matters but if you think I should redo the whole code from scratch I might have to. Oh and if it looks this way it might be because I helped myself with many tutorials and code examples out there and it can sometimes get confusing since almost nobody uses the same syntax …