alexandre Posted September 5, 2022 Author Share Posted September 5, 2022 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 . Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/2/#findComment-1600103 Share on other sites More sharing options...
mac_gyver Posted September 5, 2022 Share Posted September 5, 2022 29 minutes ago, alexandre said: 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 there is no code setting the variable $participationid in the last posted code. you are now seeing those two errors because you eliminated the fatal error, which stopped execution, that was occurring at the incorrect bind_result() statement. the sql syntax error is because the SELECT query syntax is incorrect, in that you have a * followed by a column name in the SELECT list. Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/2/#findComment-1600104 Share on other sites More sharing options...
mac_gyver Posted September 5, 2022 Share Posted September 5, 2022 21 minutes ago, alexandre said: when you look at this error here stop it. take that bind_result() statement out and leave it out. Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/2/#findComment-1600105 Share on other sites More sharing options...
alexandre Posted September 5, 2022 Author Share Posted September 5, 2022 23 minutes ago, mac_gyver said: stop it. take that bind_result() statement out and leave it out. 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. Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/2/#findComment-1600106 Share on other sites More sharing options...
dodgeitorelse3 Posted September 5, 2022 Share Posted September 5, 2022 8 hours ago, mac_gyver said: the sql syntax error is because the SELECT query syntax is incorrect, in that you have a * followed by a column name in the SELECT list. There are 2 select queries with this issue. Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/2/#findComment-1600109 Share on other sites More sharing options...
alexandre Posted September 5, 2022 Author Share Posted September 5, 2022 5 hours ago, dodgeitorelse3 said: There are 2 select queries with this issue. 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(); Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/2/#findComment-1600128 Share on other sites More sharing options...
Barand Posted September 5, 2022 Share Posted September 5, 2022 It's a waste time trying update records with derived data that can be easily got with a query when required. Don't store derived data. Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/2/#findComment-1600129 Share on other sites More sharing options...
alexandre Posted September 5, 2022 Author Share Posted September 5, 2022 (edited) 12 minutes ago, Barand said: It's a waste time trying update records with derived data that can be easily got with a query when required. Don't store derived data. 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 ? Edited September 5, 2022 by alexandre Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/2/#findComment-1600132 Share on other sites More sharing options...
Barand Posted September 5, 2022 Share Posted September 5, 2022 You don't store totals of their donations in the first place. All you need are the individual donation amounts and sum them when you need the total. Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/2/#findComment-1600134 Share on other sites More sharing options...
alexandre Posted September 5, 2022 Author Share Posted September 5, 2022 yes i agree this is much more logical as approach only i need to make a live ranking of their donations and their total donated that is why it is confusing me a bit Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/2/#findComment-1600135 Share on other sites More sharing options...
alexandre Posted September 5, 2022 Author Share Posted September 5, 2022 (edited) $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['usernames']. $row['totaldonated']. ' - ' . '<br>'; } 36 minutes ago, Barand said: You don't store totals of their donations in the first place. All you need are the individual donation amounts and sum them when you need the total. do this code is derived data and also i would like to know if it diplays only one row or all of them . Edited September 5, 2022 by alexandre Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/2/#findComment-1600137 Share on other sites More sharing options...
ginerjm Posted September 5, 2022 Share Posted September 5, 2022 (edited) I think your query should look like this: select username, sum(donation_amt) as total_donated from tablename where 1 order by total_donated desc group by username Edited September 5, 2022 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/2/#findComment-1600140 Share on other sites More sharing options...
alexandre Posted September 5, 2022 Author Share Posted September 5, 2022 9 minutes ago, ginerjm said: I think your query should look like this: select username, sum(donation_amt) as total_donated from tablename where 1 order by total_donated desc group by username it looks good , just need a little clarification here. do the number 1 is to pull 1 row as for using limit (something)? Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/2/#findComment-1600141 Share on other sites More sharing options...
Barand Posted September 5, 2022 Share Posted September 5, 2022 The "where 1" line is totally unnecessary (and looks like something produced by Dreamweaver). Ignore it. The GROUP BY line should come before the ORDER BY line. Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/2/#findComment-1600142 Share on other sites More sharing options...
ginerjm Posted September 5, 2022 Share Posted September 5, 2022 The where 1 is simply selecting all records. Not needed but I tend to include it anyway. My bad on the sequence of clauses. Tend to do that too. Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/2/#findComment-1600144 Share on other sites More sharing options...
mac_gyver Posted September 5, 2022 Share Posted September 5, 2022 On 9/4/2022 at 10:47 AM, mac_gyver said: 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. the SUM() query to get the total for any/each user should be grouping by the user's id (which is the participationid column). the usernames column should not even be in this table. this programing practice falls under the subject of data normalization and will make your queries as fast as possible, reduces the storage requirements, and makes the code/queries needed to manage the data as simple and straightforward as possible. Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/2/#findComment-1600145 Share on other sites More sharing options...
alexandre Posted September 5, 2022 Author Share Posted September 5, 2022 (edited) 31 minutes ago, mac_gyver said: the SUM() query to get the total for any/each user should be grouping by the user's id (which is the participationid column). the usernames column should not even be in this table. this programing practice falls under the subject of data normalization and will make your queries as fast as possible, reduces the storage requirements, and makes the code/queries needed to manage the data as simple and straightforward as possible. i understand thank you and i also get this error for this line of code and i cant figure what is the syntax mistake i made 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 ') VALUES (?, ?, ?,)' at line 1 in C:\xampp\htdocs\container\donation-clash\donation-clash.php:60 Stack trace: #0 C:\xampp\htdocs\container\donation-clash\donation-clash.php(60): mysqli->prepare('INSERT IGNORE I...') #1 {main} thrown in C:\xampp\htdocs\container\donation-clash\donation-clash.php on line 60 elseif (($userbalance >= $donationamountinpending) && $donationclash == true) { $stmt = $con->prepare("INSERT IGNORE INTO donationclashdetails (participationid, usernames, donationamount,) VALUES (?, ?, ?)"); $stmt->bind_param('isi', $_SESSION['id'], $_SESSION['name'], $_POST['participation']); $stmt->execute(); } else { exit; } line 60 is the INSERT line Edited September 5, 2022 by alexandre Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/2/#findComment-1600148 Share on other sites More sharing options...
ginerjm Posted September 5, 2022 Share Posted September 5, 2022 You have a dangling comma Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/2/#findComment-1600149 Share on other sites More sharing options...
alexandre Posted September 5, 2022 Author Share Posted September 5, 2022 Just now, ginerjm said: You have a dangling comma i am sorry i am french and bad in english what means a dangling comma ? Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/2/#findComment-1600150 Share on other sites More sharing options...
ginerjm Posted September 5, 2022 Share Posted September 5, 2022 If you look at the error message and examine the part of the query statement that it points at you will see what a 'dangling comma' is. Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/2/#findComment-1600151 Share on other sites More sharing options...
alexandre Posted September 5, 2022 Author Share Posted September 5, 2022 oh yeah i see , its just the dangling i never read before. anyways thnak you for your help Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/2/#findComment-1600153 Share on other sites More sharing options...
ginerjm Posted September 5, 2022 Share Posted September 5, 2022 Dangling can refer to perhaps a thread hanging off of a new shirt or a strand of hair hanging on your forehead. 1 Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/2/#findComment-1600154 Share on other sites More sharing options...
alexandre Posted September 5, 2022 Author Share Posted September 5, 2022 (edited) just like that because i am bored and i am searching this answer what would be the most secure and efficient way as an alternative for mysqli_query() whcich is telling me that it is deprecated.. Deprecated: mysqli_query(): Passing null to parameter #2 ($query) of type string is deprecated in C:\xampp\htdocs\container\donation-clash\donation-clash.php on line 101 i am almost sure that barrand got a strong opinion about it 😄 from where i am asking . Edited September 5, 2022 by alexandre Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/2/#findComment-1600156 Share on other sites More sharing options...
ginerjm Posted September 5, 2022 Share Posted September 5, 2022 Show us the code that is giving you this message. You should always do this. Mysqli is not (yet) deprecated. Mysql is deprecated and has been for a few years. Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/2/#findComment-1600157 Share on other sites More sharing options...
alexandre Posted September 5, 2022 Author Share Posted September 5, 2022 (edited) 8 minutes ago, ginerjm said: Show us the code that is giving you this message. You should always do this. Mysqli is not (yet) deprecated. Mysql is deprecated and has been for a few years. $stmt = $con->prepare('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['usernames']. $row['totaldonated']. ' - ' . '<br>'; } } //here is the prt of code ho i think i just saw lol Edited September 5, 2022 by alexandre Quote Link to comment https://forums.phpfreaks.com/topic/315273-my-life-have-ended-help-please/page/2/#findComment-1600159 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.