alexandre Posted September 4, 2022 Share Posted September 4, 2022 !!! 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. Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/ Share on other sites More sharing options...
Solution maxxd Posted September 4, 2022 Solution Share Posted September 4, 2022 (edited) Not sure how that would have happened, but dude I feel ya' - losing WIP sucks. Check to see if your editor created a temp file somewhere or if there's an automated backup. Obviously, this is one of the benefits of using git but if you're not or you didn't commit or push, it may be rough. How exactly were you running the script that an infinite loop could have wiped your file? Edited September 4, 2022 by maxxd 1 Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/#findComment-1600055 Share on other sites More sharing options...
alexandre Posted September 4, 2022 Author Share Posted September 4, 2022 (edited) 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 Edited September 4, 2022 by alexandre Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/#findComment-1600056 Share on other sites More sharing options...
alexandre Posted September 4, 2022 Author Share Posted September 4, 2022 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. Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/#findComment-1600057 Share on other sites More sharing options...
maxxd Posted September 4, 2022 Share Posted September 4, 2022 That is really strange; try opening the file in a plain text editor. It almost looks like it could be an issue with your editor (atom? i don't recognize the icon). Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/#findComment-1600058 Share on other sites More sharing options...
alexandre Posted September 4, 2022 Author Share Posted September 4, 2022 Yup it is atom Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/#findComment-1600059 Share on other sites More sharing options...
alexandre Posted September 4, 2022 Author Share Posted September 4, 2022 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. Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/#findComment-1600060 Share on other sites More sharing options...
maxxd Posted September 4, 2022 Share Posted September 4, 2022 Not really sure how my post was the answer - did you recover your file? Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/#findComment-1600061 Share on other sites More sharing options...
alexandre Posted September 4, 2022 Author Share Posted September 4, 2022 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 🤯 Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/#findComment-1600062 Share on other sites More sharing options...
alexandre Posted September 4, 2022 Author Share Posted September 4, 2022 (edited) 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(); } Edited September 4, 2022 by alexandre Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/#findComment-1600063 Share on other sites More sharing options...
maxxd Posted September 4, 2022 Share Posted September 4, 2022 It still seems weird that even having to hard reboot the system would wipe out a file that clearly had been saved. Admittedly, if Windows was already having trouble it has been known to happen; it totally sucks, but yeah - computers barf sometimes. As to your second question; no idea, dude. I do however look askance at the `$stmt->close();` line as I'm not sure one really ever needs to close a DB connection in PHP, it handles that pretty well on its own. Somebody here will I hope speak up if I'm mistaken on that. What you've posted will overwrite variables of the same name if the code you've posted is nested. For instance, if you're looping through a result set defined as `$result` and you have the code you've posted, then yeah - `$result` will change as of the first iteration of the internal loop (the code you posted) and you'll get unexpected results. I will also say that if you're running a query within a loop based on the result of another query, there's probably a bigger issue with the code. Post what you've got. Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/#findComment-1600064 Share on other sites More sharing options...
alexandre Posted September 4, 2022 Author Share Posted September 4, 2022 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!'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/#findComment-1600065 Share on other sites More sharing options...
maxxd Posted September 4, 2022 Share Posted September 4, 2022 As this has moved to a new issue, please start a fresh thread with your latest question. Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/#findComment-1600067 Share on other sites More sharing options...
alexandre Posted September 4, 2022 Author Share Posted September 4, 2022 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. Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/#findComment-1600071 Share on other sites More sharing options...
mac_gyver Posted September 4, 2022 Share Posted September 4, 2022 (edited) 14 hours ago, alexandre said: i have a question do this code changes the variables in which i fetched data higher in the script? i suspect you are asking this because your code and variables aren't behaving the way you expect? the reason most of your conditional tests are not working and variables are being changed, is because one = is an assignment operator and two == is a comparison operator. when you have a statement like - if($donationclash = false), this assigns false to the variable, then tests the result, which will be a false value. all these conditional tests against variables should use two ==. if($donationclash == false), this tests if the variable is equal to a false value and leaves the value in the variable as is. a comment about the use of the $donationclash variable throughout this code. since your program logic is halting execution if the $DONATIONCLASHTIME is false, there's no point in the $donationclash variable at all. all the rest of the code on the page after the $DONATIONCLASHTIME test and its message won't be executed. here's a list of issues with the current code - there are no helpful comments in the code describing what the goal of each section is. this makes it almost impossible for anyone to help with your code. switch to the much simpler and more consistent PDO database extension. it treats the result of a non-prepared and a prepared query identically. this alone will eliminate about half of the code dealing with database queries. don't copy variables to other variables for nothing. just use the original variables. this accounts for close to half of the existing lines of code. this is just a waste of typing and is making more work for you in keeping track of everything and makes it almost impossible for anyone to help. don't use multiple names for the same thing. this requires you to keep track of which name you are using and makes it next to impossible for someone to help. use under scores _ to separate the words making up names of things. make the database connection in an initialization section at the top of your code and don't repeatedly require (once) the connection file. only store the user's id in session variable, named user_id or similar, to indicate who the logged in user is. this will either be set or it won't. query on each page request to get any other user information, such as the username, permissions, ... you have mistakes in most of the if() comparisons. one = is an assignment operator. two == is a comparison operator. there are other logic mistakes with what the else and else if logic is doing, that would be easier to see if you consistently indent your code. use 'require' for things that your code must have for it to work. include/require are not functions. the () around the value does nothing but clutter up your code with unnecessary typing. be consistent. you are using include/require_once and echo/print at different points. don't use a loop to fetch data from a query that will match at most one row of data. just fetch the single row of data. why do you have an if() around the prepare() calls? you don't do anything if they fail and since the execute() calls can fail, why don't you have conditional tests for them too? instead of writing out conditional logic for each database statement that can fail, use exceptions for errors and in most cases simply let php catch and handle any database exception, simplifying the code. the only time your code should catch and handle a database statement error/exception is for user recoverable errors, such as when inserting/updating duplicate or out of range user submitted data. in all other cases, don't put any logic in your code and simply let php catch and handle the error/exception. build sql query statements in php variables. this will make testing easier and help to eliminate typo mistakes by separating the sql query syntax as much as possible from the php syntax. you should always fetch all the data that a query returns, which is why you went to the trouble of executing a query in the first place, so there should not be any case where you need to close a prepared query. don't store redundant data in multiple locations. you are storing the user's id in the donationclashdetails. that's all the user information you need. you can get any other user information via the user's id. any one conditional test can either be true or false. you don't need test for the false case after you have tested for the true case. if a test is not true, it must be false. the $stmt->store_result() and $stmt->bind_result() after the INSERT query don't belong there and may be producing errors. do you have php's error_reporting set to E_ALL and display_errors set to ON, preferably in the php.ini on your system, so that php will help you by reporting and displaying all the errors it detects? the SELECT ... FROM donationclashdetails WHERE participationid = ? query, right after the INSERT query, and the associated repetitive logic, is unnecessary. the php code for any page should be laid out in this general order - initialization post method form processing get method business logic - get/produce data needed to display the page html document post method form processing should - detect if a post method form was submitted, which you are doing. however, all the form processing code goes inside this conditional block of code. yours isn't. keep the form data as a set, in an array variable, then operate on elements in this array throughout the rest of the code trim all the inputs at once validate all inputs, storing validation errors in an array using the field name as the array index after the end of the validation logic, if there are no errors (the array holding the errors will be empty), use the submitted form data after the end of the form processing logic, if there are no errors, perform a redirect to the exact same url of the current page to cause a get request. this will prevent the browser from trying to resubmit the form data to display a one-time success message, store it in a session variable, then test, display, and clear the variable at the appropriate location in the html document. if there are errors at step #5, the code will continue on to (re)display the html document. you would test/display any errors and redisplay the form, populating the field value(s) with any existing data. apply htmlentities() to any dynamic value when you output it in a html context Edited September 4, 2022 by mac_gyver 1 Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/#findComment-1600078 Share on other sites More sharing options...
alexandre Posted September 4, 2022 Author Share Posted September 4, 2022 (edited) 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 ? Edited September 4, 2022 by alexandre Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/#findComment-1600085 Share on other sites More sharing options...
maxxd Posted September 4, 2022 Share Posted September 4, 2022 You can use prepared queries for all query types, and if the SQL itself contains any values not hard-coded in the SQL string you absolutely should. That having been said, if you're doing a straight select without external input of any sort, don't bother. It'll just add an (admittedly small) amount of overhead. From your posted code it looks like you're actually doing that already. As mac_gyver pointed out, you should be seeing additional PHP errors - I see several missing semicolons in what you posted. I haven't used atom, but it should be pointing out those types of errors for you. Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/#findComment-1600089 Share on other sites More sharing options...
mac_gyver Posted September 4, 2022 Share Posted September 4, 2022 3 hours ago, alexandre said: reduce the risk of such threat by using prepared queries prepared queries provide fool-proof protection against sql special characters in a data value breaking the sql query syntax, which is how sql injection is accomplished. you are already using prepared queries with the mysqli extension. however, as stated, the PDO extension is much simpler and more consistent. for the SELECT query that's getting the current user's row of data, this what it looks like using mysqli (with the if(){} and ->close() removed) - $stmt = $con->prepare("SELECT userbalance, totaleventjoined, totalpifcoingained, totaldonationdc, userlevel, userexperience FROM accounts WHERE id = ?"); $stmt->bind_param('i', $_SESSION['id']); $stmt->execute(); $stmt->bind_result($userbalance, $totaleventjoined, $totalpifcoingained, $totaldonationdc, $userlevel, $userexperience); $stmt->fetch(); and here's what that looks like using PDO - $stmt = $pdo->prepare("SELECT userbalance, totaleventjoined, totalpifcoingained, totaldonationdc, userlevel, userexperience FROM accounts WHERE id = ?"); $stmt->execute([ $_SESSION['id'] ]); $user_data = $stmt->fetch(); there's no need for explicit binding of inputs or for the result. you can directly fetch data from a prepared PDO query exactly the same as for a non-prepared query. Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/#findComment-1600090 Share on other sites More sharing options...
alexandre Posted September 4, 2022 Author Share Posted September 4, 2022 (edited) 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; } ?> Edited September 4, 2022 by alexandre Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/#findComment-1600091 Share on other sites More sharing options...
alexandre Posted September 4, 2022 Author Share Posted September 4, 2022 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 Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/#findComment-1600093 Share on other sites More sharing options...
mac_gyver Posted September 4, 2022 Share Posted September 4, 2022 since the error mentions the bind_result() statement, the cause of this error has already been stated - 6 hours ago, mac_gyver said: the $stmt->store_result() and $stmt->bind_result() after the INSERT query don't belong there and may be producing errors. an INSERT (now a REPLACE) query doesn't have a result set, so there's nothing for bind_result to bind to. at this point we are just repeating information already given. you need to spend more time on your own trying to solve problems. Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/#findComment-1600094 Share on other sites More sharing options...
alexandre Posted September 4, 2022 Author Share Posted September 4, 2022 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 Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/#findComment-1600096 Share on other sites More sharing options...
alexandre Posted September 4, 2022 Author Share Posted September 4, 2022 38 minutes ago, mac_gyver said: since the error mentions the bind_result() statement, the cause of this error has already been stated - an INSERT (now a REPLACE) query doesn't have a result set, so there's nothing for bind_result to bind to. at this point we are just repeating information already given. you need to spend more time on your own trying to solve problems. 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. Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/#findComment-1600099 Share on other sites More sharing options...
mac_gyver Posted September 5, 2022 Share Posted September 5, 2022 the error is occurring on line 63. based on the last code you posted, the bind_result() nearest that line is the one after the INSERT/REPLACE query, which doesn't have a result set to fetch data from. if you are removing the bind_result() at about line 16 in the last posted code, that one does belong there because it is associated with a SELECT query, which does have a result set. i seriously recommend that before you waste any more time on this, that you switch to the much simpler PDO extension. Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/#findComment-1600101 Share on other sites More sharing options...
alexandre Posted September 5, 2022 Author Share Posted September 5, 2022 (edited) 20 minutes ago, mac_gyver said: the error is occurring on line 63. based on the last code you posted, the bind_result() nearest that line is the one after the INSERT/REPLACE query, which doesn't have a result set to fetch data from. if you are removing the bind_result() at about line 16 in the last posted code, that one does belong there because it is associated with a SELECT query, which does have a result set. i seriously recommend that before you waste any more time on this, that you switch to the much simpler PDO extension. 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 Edited September 5, 2022 by alexandre Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/#findComment-1600102 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.