Jump to content

I might be blind can't see why this code isn't working


beanymanuk

Recommended Posts

I might be blind can't see why this code isn't working

 

I have this piece of code but its not inserting my results into the database.

 

function mysponsors() {
global $wpdb;

$get_sponsors_card = $wpdb->get_results("SELECT cause, email, SUM(amout) as total_amount 
FROM cashdepo
GROUP BY email, cause");
					foreach ($get_sponsors_card as $get_sponsors_card){
					echo $get_sponsors_card->cause;
					$cause = $get_sponsors_card->cause;
					echo "<br>";
					echo $get_sponsors_card->email;
					echo "<br>";
					$email = $get_sponsors_card->email;

					echo $get_sponsors_card->total_amount;
					$total_amount = $get_sponsors_card->total_amount;
					echo "<br>";
					$get_sponsors_card2 = $wpdb->get_results("SELECT DISTINCT firstname 
FROM accountinfo
WHERE email = '$email'");
					foreach ($get_sponsors_card2 as $get_sponsors_card2){
					echo $get_sponsors_card2->firstname;
					$firstname = $get_sponsors_card2->firstname;
					echo "<br><br>";
					}

// INSERT INTO TABLE
$sumcashinsert = mysql_query ("INSERT INTO cashsumtotals (cause, email, total_amount, firstname) VALUES('$cause', '$email', '$total_amount', '$firstname')");	
					}

}

Link to comment
Share on other sites

I have tried moving code about and tried just inserting into the database with

 

$sumcashinsert = mysql_query ("INSERT INTO cashsumtotals (cause, email, total_amount, firstname) VALUES('$cause', '$email', '$total_amount', '$firstname')");	

 

So I'm now thinking the problem must be somewhere else on the site and not with this code

Link to comment
Share on other sites

Have you tried checking to see if the query has succeeded by checking the results it returns? Also, take a look at the output of mysql_error.

 

Another good idea is to store your query in a variable and echo it to make sure it looks as you expect.

 

Sorry, but your code is very poorly formatted or a I would actually look at it.

Link to comment
Share on other sites

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.