简体   繁体   中英

PHP doesn't recognise form elements from Javascript

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!

价值观是“他”,“她”而不是“为他”,“为她”

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM