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')");	
					}

}

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.