0

HTML: saucydares.freehostia.com/saucy.php I should just add that while there are no images, the site contains adult themes so isn't work safe.

PHP:

    <?php

    mysql_connect("mysql4.freehostia.com", sebsal2_db, "");

    function him()
    {
    $HIMquery = "SELECT dares FROM sebsal2_db.him UNION SELECT dares FROM sebsal2_db.other ORDER BY Rand() LIMIT 1";
    $HIMresult = mysql_query($HIMquery);
    while ($HIMrow = mysql_fetch_array($HIMresult, MYSQL_NUM)) {echo "$HIMrow[0]";}
    }

    function her()
    {
    $HERquery = "SELECT dares FROM sebsal2_db.her UNION SELECT dares FROM sebsal2_db.other ORDER BY Rand() LIMIT 1";
    $HERresult = mysql_query($HERquery);
    while ($HERrow = mysql_fetch_array($HERresult, MYSQL_NUM)) {echo "$HERrow[0]";}
    }

    function double()
    {
    $DOUBLEquery = "SELECT dares FROM sebsal2_db.double ORDER BY Rand() LIMIT 1";
    $DOUBLEresult = mysql_query($DOUBLEquery);
    while ($DOUBLErow = mysql_fetch_array($DOUBLEresult, MYSQL_NUM)) {echo "$DOUBLErow[0]";}
    }

    function himlong()
    {
    $HIMLONGquery = "SELECT dares FROM sebsal2_db.him2 UNION SELECT dares FROM sebsal2_db.other2 ORDER BY Rand() LIMIT 1";
    $HIMLONGresult = mysql_query($HIMLONGquery);
    while ($HIMLONGrow = mysql_fetch_array($HIMLONGresult, MYSQL_NUM)) {echo "$HIMLONGrow[0]";}
    }

    function herlong()
    {
    $HERLONGquery = "SELECT dares FROM sebsal2_db.her2 UNION SELECT dares FROM sebsal2_db.other2 ORDER BY Rand() LIMIT 1";
    $HERLONGresult = mysql_query($HERLONGquery);
    while ($HERLONGrow = mysql_fetch_array($HERLONGresult, MYSQL_NUM)) {echo "$HERLONGrow[0]";}
    }

    function doublelong()
    {
    $DOUBLELONGquery = "SELECT dares FROM sebsal2_db.double2 ORDER BY Rand() LIMIT 1";
    $DOUBLELONGresult = mysql_query($DOUBLELONGquery);
    while ($DOUBLELONGrow = mysql_fetch_array($DOUBLELONGresult, MYSQL_NUM)) {echo "$DOUBLELONGrow[0]";}
    }

var_dump($_POST)

/*    $mode = mysql_real_escape_string($_POST['mode']);
    $player = mysql_real_escape_string($_POST['player']);
    echo $player;
    echo $mode;

    if ($player=="For him" && $mode=="Classic Collection") {
    him();
    }

    if ($player=="For her" && $mode=="Classic Collection") {
    her();
    }

    if ($player=="Double dare" && $mode=="Classic Collection") {
    double();
    }

    if ($player=="For him" && $mode=="The Long Game") {
    himlong();
    }

    if ($player=="For her" && $mode=="The Long Game") {
    herlong();
    }

    if ($player=="Double dare" && $mode=="The Long Game") {
    doublelong();
    }
*/
    ?>

It is designed to read two drop down lists and display a random field from a mySQL database depending on the combination. Echoing the variables is not permanent, was just a test. Two problems:

  • Using var_dump($_POST), if you select Classic Collection it sees all the options in the right hand box as "For him" and if you select The Long Game it sees them as "For her".

  • For this reason the if statements don't work.

Thanks for your replies!

9
  • have you tried doing a var_dump($_POST) to see what is actually being submitted? Commented Jul 29, 2010 at 19:06
  • See my comment to Mchl's answer -- the issue is the data.php file you are posting the Javascript to. Whatever is assigning "For him" as the value to player, that's the issue. Commented Jul 29, 2010 at 20:35
  • thanks for your reply. can you see anything specific? I still can't find it... Commented Jul 29, 2010 at 20:45
  • the javascript should be assigning the value based on the dropdown selection. the value is only turned into a variable in php. Commented Jul 29, 2010 at 20:47
  • Are you sure that's data.php? Again, the post value for "player" is set to "her", but that var_dump is displaying it as "For her" so there's some transformation happening somewhere. Commented Jul 29, 2010 at 21:02

2 Answers 2

1

Values are 'him','her' not 'For him','For her'

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for your reply. How is that relevant when the variable is based on the selected text as opposed to the values of the options?
Haha :) You may be on the right lines though as the only bit that doesn't work is the second box.
No, I think you're on to some Mchl -- because the var_dump or whatever it is prints "For him" but the selected value is definitely "her" -- so something is off on the back-end, not the Javascript, I think.
0

Your code could use some serious condensing. The if statements should be nested, and the functions could be condensed to one function using parameters. A possible function signature:

function game($player, $mode)

Then base your business logic and queries inside the function on the parameters.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.