Login | Register | FAQ
Anonymous

PHP - Retrieving From Ajax

+ Post a reply

7 posts Page 1 of 1


PHP - Retrieving From Ajax

by soccerwebsitemaker » Fri Jun 08, 2012 9:10 pm

$previouschoice = $_POST["bluebgradio"];

I have some successful AJAX code running that...

sends to the url profile.php the data 'blueBGhas: "yes"' if the radio button is clicked...and if a different radio button is clicked it sends data 'greenBGhas: "yes"'

But the database is not updated...

Can anyone fix up the code so it does that correctly?


JavaScript Code:


Code: Select all
//AJAX STUFF

      $(document).ready(function()
      
      {
      
      $('#bluebgradio').click(function()
      
      {
      
      $.ajax(
      
      {
      
      type: "POST",
      
      url: "profile.php",
      
      data: {blueBGhas: "yes"}

      });

      });

      $('#greenbgradio').click(function()
      
      {
      
      $.ajax(
      
      {
      
      type: "POST",
      
      url: "profile.php",
      
      data: {greenBGhas: "yes"}

      });

      });

      });







profile.php code:



Code: Select all
$previouschoice = $_POST['data'];

if ($previouschoice == 'blueBGhas: "yes"')

{

$superSTRsql = "UPDATE Customize SET BlueBGhas='yes' WHERE Username = '$username'";

$superSTRsql1 = "UPDATE Customize SET YellowBGhas='no' WHERE Username = '$username'";

$superSTRsql2 = "UPDATE Customize SET GreenBGhas='no' WHERE Username = '$username'";

$superSTRsql3 = "UPDATE Customize SET RedBGhas='no' WHERE Username = '$username'";

$superSTRsql4 = "UPDATE Customize SET PurpleBGhas='no' WHERE Username = '$username'";

$superSTRsql5 = "UPDATE Customize SET BlackBGhas='no' WHERE Username = '$username'";

mysql_query($superSTRsql, $connection);

mysql_query($superSTRsql1, $connection);

mysql_query($superSTRsql2, $connection);

mysql_query($superSTRsql3, $connection);

mysql_query($superSTRsql4, $connection);

mysql_query($superSTRsql5, $connection);

}

else if ($previouschoice == 'greenBGhas: "yes"')

{

$superSTRsql = "UPDATE Customize SET BlueBGhas='no' WHERE Username = '$username'";

$superSTRsql1 = "UPDATE Customize SET YellowBGhas='no' WHERE Username = '$username'";

$superSTRsql2 = "UPDATE Customize SET GreenBGhas='yes' WHERE Username = '$username'";

$superSTRsql3 = "UPDATE Customize SET RedBGhas='no' WHERE Username = '$username'";

$superSTRsql4 = "UPDATE Customize SET PurpleBGhas='no' WHERE Username = '$username'";

$superSTRsql5 = "UPDATE Customize SET BlackBGhas='no' WHERE Username = '$username'";

mysql_query($superSTRsql, $connection);

mysql_query($superSTRsql1, $connection);

mysql_query($superSTRsql2, $connection);

mysql_query($superSTRsql3, $connection);

mysql_query($superSTRsql4, $connection);

mysql_query($superSTRsql5, $connection);

}






//And a few lines later...






if ($blueBGhas == 'yes')

{

echo '<style>body { background: blue; }</style>';

}

else if ($greenBGhas == 'yes')

{

echo '<style>body { background: green; }</style>';

}







This is urgent please help!



Problem: Background color does not change and database is not updated.
User avatar

soccerwebsitemaker

  • Posts: 139
  • Joined: Sat Dec 31, 2011 6:25 pm
--
Coins. Profile. Games. Chat. Fun.

CoinAwards.

Check it out at http://www.coinawards.net63.net/

Re: PHP - Retrieving From Ajax

by XainPro » Sat Jun 09, 2012 5:56 am

1st of all i would say before writing the code make your structure corect your whole structure is wrong make a field name background in users table and intead of saving yes no just save the color name in it.
if its blue then save blue etc make it step by step 1st step is to save the database use 1 query not 5 or 7 queries to just make a single thing done
see the pic i have attached.

Attachments

  1. test.png (6.02 KiB) Downloaded 871 times

User avatar

XainPro

  • Posts: 3661
  • Joined: Fri Feb 17, 2012 8:10 pm

Re: PHP - Retrieving From Ajax

by soccerwebsitemaker » Sat Jun 09, 2012 4:39 pm

Ok so I'm doing that but how do i get the data sent?
User avatar

soccerwebsitemaker

  • Posts: 139
  • Joined: Sat Dec 31, 2011 6:25 pm
--
Coins. Profile. Games. Chat. Fun.

CoinAwards.

Check it out at http://www.coinawards.net63.net/

Re: PHP - Retrieving From Ajax

by soccerwebsitemaker » Sat Jun 09, 2012 7:59 pm

Hold up, never mind: I FINALLY FIGURED IT OUT! ONE WEEK OF STRESS FINALLY I GOT IT YES!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!





WOOOOOOHOOOOOOOOOOOOOO!
User avatar

soccerwebsitemaker

  • Posts: 139
  • Joined: Sat Dec 31, 2011 6:25 pm
--
Coins. Profile. Games. Chat. Fun.

CoinAwards.

Check it out at http://www.coinawards.net63.net/

Re: PHP - Retrieving From Ajax

by XainPro » Sun Jun 10, 2012 6:27 am

through AJAX ?
User avatar

XainPro

  • Posts: 3661
  • Joined: Fri Feb 17, 2012 8:10 pm

Re: PHP - Retrieving From Ajax

by soccerwebsitemaker » Thu Jun 14, 2012 12:13 am

Yessssssssssssssssssssssssssssssssssssssssssssssssssssssssssss.............................................
User avatar

soccerwebsitemaker

  • Posts: 139
  • Joined: Sat Dec 31, 2011 6:25 pm
--
Coins. Profile. Games. Chat. Fun.

CoinAwards.

Check it out at http://www.coinawards.net63.net/

Re: PHP - Retrieving From Ajax

by XainPro » Thu Jun 14, 2012 11:20 am

woo i am happy for you good luck bro !
you really make this happen and build what you really want hats off
User avatar

XainPro

  • Posts: 3661
  • Joined: Fri Feb 17, 2012 8:10 pm


+ Post a reply

Page 1 of 1