简体   繁体   中英

Problem with the html/php radio buttons submit errors

So here's my form with php code (in a file)

 <form method="post" action="<?php echo $PHP_SELF;?>"> 
    <?php
     include 'find.php';
    ?>
    <input type="Submit"name="choose" value ="Find" />
    </form>

<?php
mysql_connect ("localhost", "root","") or die ('Error : '.mysql_error());
mysql_select_db("keyword");


switch ($_POST['choose']) {

      case 'Find':

This is my find.php

 <?php 
 mysql_connect ("localhost", "root","") or die ('Error : '.mysql_error());
mysql_select_db("keyword");
$res = mysql_query("SELECT distinct question_text FROM questions");
while($row = mysql_fetch_assoc($res))
{
   echo "<input type='radio' name='choose' value='" . $row['question_text'] . "' /> ". $row['question_text'] . '<br />';
}
 ?>

I can't get the result.It's syntax error free but no result for the functions in switch case :Find

Is my submit values correctly paired ? Can someone check it for me please !!!TIA

Try giving your submit button a different name.
Now both the radiobuttons and the submitbutton carry the same name.

Try something like:

 <form method="post" action="<?php echo $PHP_SELF;?>"> 
    <?php
     include 'find.php';
    ?>
    <input type="Submit" name="send" value ="Find" />
    </form>

I would guess that the table questions doesnt have any data in it. Verify this by running

SELECT distinct question_text FROM questions against it in MySQL client.

If this isnt causing the problem, run the find.php script on its own by calling it from a browser.

To make debugging easier, make sure that you've got error reporting switched on.

Finally, although it's ok-ish for development, for security's sake, avoid using root for php scripts, and change the password from being blank.

You might want to check that the form output is what you expect it to be in the browser by looking at the source when you access the page. That should give you some pointers on what's wrong. Having the same name for the radio buttons, and the submit button probably doesn't help either.

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