PHP $_POST['$var']获取动态PHP表单的名称


PHP $_POST['$var'] get the name of a dynamic php form

//this is the php code that i call in another file
    if ( isset($_POST['star'])){
        $check_vote = $_POST['star'];
        $new_rate = 0;
        ***$video1_id = $_POST["$video_id"];*** //the problem is here
        $find_video = mysqli($con, "SELECT * FROM videos WHERE video_id='$video_id1'");
        // and this is the html code that another php function echoes//

form name='$video_id' method='POST'                             
input class='star star-5' id='star-5' type='radio' name='star' value='5'/>                              
<label class='star star-5' for='star-5'></label>                                
<input class='star star-4' id='star-4' type='radio' name='star' value='4'/>                         
<label class='star star-4' for='star-4'></label>                            
<input class='star star-3' id='star-3' type='radio' name='star' value='3'/>                             
<label class='star star-3' for='star-3'></label>
<input class='star star-2' id='star-2' type='radio' name='star' value='2'/>
<label class='star star-2' for='star-2'></label>
<input class='star star-1' id='star-1' type='radio' name='star' value='1'/>
<label class='star star-1' for='star-1'></label>    
<input type='submit' name='$video_id' value='Vote' id='$video_id'>                  
</form> 
// my problem is that i want to take the variable $video_id(either form the form either from the submit-button) to search for the specific video but i cant. i tried $video1_id = $_POST["$video_id"]; and $video1_id = $_POST['$video_id']; and this $video1_id = $_POST[$video_id]; and this $video1_id = $_POST['.$video_id'];

感谢您的宝贵时间

你不能像$_POST["$video_id"]那样获得变量的值,从一个带有文本或隐藏字段的字段发送它,然后从另一边获得它。

你必须把你的php代码从html中分离出来。"$blabla"语法错误。在PHP中添加PHP开始和结束标签,比如

所以你可以在html 中使用你的PHP代码例如

<h1><?=$video_id?> </h1>
<input type="hidden" name="vID" value="<?=$video_id?>" />

,然后写成

$myVideoId = $_POST["vID"];

//解决方案在PHP echo HTML代码是这样的…

form name='$video_id' method='POST'                             
input class='star star-5' id='star-5' type='radio' name='star' value='5'/>                              
label class='star star-5' for='star-5'></label>                                
input class='star star-4' id='star-4' type='radio' name='star' value='4'/>                         
label class='star star-4' for='star-4'></label>                            
input class='star star-3' id='star-3' type='radio' name='star' value='3'/>                             
label class='star star-3' for='star-3'></label>
input class='star star-2' id='star-2' type='radio' name='star' value='2'/>
label class='star star-2' for='star-2'></label>
input class='star star-1' id='star-1' type='radio' name='star' value='1'/>
label class='star star-1' for='star-1'></label>    
input type='submit' name='$video_id' value='Vote' id='$video_id'>                  
/form

//在另一个函数中正确的PHP代码是这个

if (isset($_POST['star']) &&收取($ _POST [' video_id '])) {$check_vote = $_POST['star'];

        $new_rate = 0;
        $video_id = $_POST['video_id'];
        $sql = " SELECT * FROM videos WHERE video_id = '$video_id' ";
        $find_video = mysqli_query($con, $sql);