dougupang0901
dougupang0901
2014-02-11 15:55

单选按钮值:“on”

已采纳

i have this form, when user clicks on the submit button, a script open a popup where i need to print the radio button value. My problem is the printed value on the popup window: "on" but the result should be a number (selected person's id)

My PHP Code:

    <form method="post" action="edit.php" onsubmit="target_popup(this,'edit.php')"><input type="submit" value="Modifica Giocatore"  /><br /><br /><br />
                <?php
                    //my queries (work)
                ?>

                <table cellspacing="2" cellpadding="2">
                <tr>
                <th></th>
                <th>Name</th>
                <th>Surname</th>
                </tr>

                <?php
                    $i=0;
                    while ($i < $num) {
                        $id=mysql_result($results,$i,"ID");
                        $name=mysql_result($results,$i,"Name");
                        $surname=mysql_result($results,$i,"Surname");
                ?>

                <tr>
                    <td><input type="radio" name="radioEdit" value"<?= $id; ?>"  /><?= $id; ?></td>
                    <td><?=$name?></td>
                    <td><?=$surname?></td>
                </tr>


                <?php 
                    $i++; 
                    } 
                ?> 

                <?php

                    echo "</table></form>"
                ?>

And this is my script:

    function target_popup(form,page) 
    {
        window.open(page, 'formpopup', 'left=100,top=100,width=600,height=400,menubar,toolbar,resizable');
        form.target = 'formpopup';
    }

edit.php file:

    <?php
        $prova = $_POST['radioEdit'];
        echo $prova;        
    ?>

Thanks.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享
  • 邀请回答

2条回答

  • dongzou7134 dongzou7134 7年前

    The only way I could get this to work was to use sessions.

    Here is what I could test without setting up an entire DB.

    PHP

    <?php
    session_start();
    $id="12345"; // test ID number
    
    // works with sessions
    $prova = $_POST['radioEdit'] = $_SESSION['id'] = $id;
    echo $prova;
    ?>
    
    <form method="post" action="edit.php" onsubmit="target_popup(this,'edit.php')">
    <td><input type="radio" name="radioEdit" value"<?php echo $id; ?>"  /><?= $id; ?></td>
    <input type="submit" value="Modifica Giocatore"  />
    </form>
    
    <script>
        function target_popup(form,page) 
        {
            window.open(page, 'formpopup', 'left=100,top=100,width=600,height=400,menubar,toolbar,resizable');
            form.target = 'formpopup';
        }
    </script>
    

    edit.php

    <?php
    session_start();
    echo $_SESSION['id'];
    echo $id;
    echo "<br>";
    var_dump($_SESSION['id']);
    ?>
    
    点赞 评论 复制链接分享
  • douzhongpi9734 douzhongpi9734 7年前

    What happens when you echo $id? Are you sure that it returns a value? Also isn't <?= ;?> considered really old and deprecated PHP? You should be using <?php echo ;?>

    点赞 评论 复制链接分享