Jump to content

My life have ended help please


Go to solution Solved by maxxd,

Recommended Posts

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 .

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.

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. 

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.

 

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();

 

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 by alexandre
$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 by alexandre
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)?

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.

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 by alexandre

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 by alexandre
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 by alexandre
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.