beanymanuk Posted January 6, 2012 Share Posted January 6, 2012 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')"); } } Quote Link to comment https://forums.phpfreaks.com/topic/254473-i-might-be-blind-cant-see-why-this-code-isnt-working/ Share on other sites More sharing options...
trq Posted January 6, 2012 Share Posted January 6, 2012 What have you done to debug the issue? Quote Link to comment https://forums.phpfreaks.com/topic/254473-i-might-be-blind-cant-see-why-this-code-isnt-working/#findComment-1304789 Share on other sites More sharing options...
beanymanuk Posted January 6, 2012 Author Share Posted January 6, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/254473-i-might-be-blind-cant-see-why-this-code-isnt-working/#findComment-1304790 Share on other sites More sharing options...
trq Posted January 6, 2012 Share Posted January 6, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/254473-i-might-be-blind-cant-see-why-this-code-isnt-working/#findComment-1304791 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.