Php 表单使用单选按钮选择主图像

Php 表单使用单选按钮选择主图像,php,Php,我试图找出处理表单的最佳方法,该表单将用于选择主赞助商(类似于从收藏中选择主图像)并通过替换值更新数据库 这是我试图用来做更新的表单 <form action="" method="POST"> <table id='partnertable'> <tr id='head'> <th id='col4'>Logo</th

我试图找出处理表单的最佳方法,该表单将用于选择主赞助商(类似于从收藏中选择主图像)并通过替换值更新数据库

这是我试图用来做更新的表单

<form action="" method="POST">                
          <table id='partnertable'>
                <tr id='head'>
                    <th id='col4'>Logo</th>
                    <th id='col1'>Partner</th>
                    <th id='col2'>URL</th>
                    <th id='col3'>Actions</th>
                    <th id='col4'>Main Sponsor</th>

                </tr><tr class='details'>

                    <td id='col4'><img id='logos' src='../media/images/logo1.png'/></td>
                    <td id='col1'>Pure</td>
                    <td id='col2'>http://www.pureconcepts.com.mt/</td>
                    <td id='col3'><a href='delete.php?partnerID=21'>Delete</a>|<a href='logo.php?logoID=21'>Edit</a></td>
                    <input type='hidden' name='partner' value='21'></input>
                    <td id='col4'><input type= 'radio' name='sponsor' value='4'/>
                </tr><tr class='details'>

                    <td id='col4'><img id='logos' src='../media/images/logo2.png'/></td>
                    <td id='col1'>wuerth</td>
                    <td id='col2'>http://www.wuerth.com.mt/</td>
                    <td id='col3'><a href='delete.php?partnerID=22'>Delete</a>|<a href='logo.php?logoID=22'>Edit</a></td>
                    <input type='hidden' name='partner' value='22'></input>
                    <td id='col4'><input type= 'radio' name='sponsor' value='4'/>
                </tr><tr class='details'>

                    <td id='col4'><img id='logos' src='../media/images/logo3.png'/></td>
                    <td id='col1'>magri cycles</td>
                    <td id='col2'>http://www.magricycles.com/</td>
                    <td id='col3'><a href='delete.php?partnerID=23'>Delete</a>|<a href='logo.php?logoID=23'>Edit</a></td>
                    <input type='hidden' name='partner' value='23'></input>
                    <td id='col4'><input type= 'radio' name='sponsor' value='4'/>
                </tr><tr class='details'>

                    <td id='col4'><img id='logos' src='../media/images/logo7.png'/></td>
                    <td id='col1'>powerade</td>
                    <td id='col2'>http://www.gsd.com.mt/</td>
                    <td id='col3'><a href='delete.php?partnerID=26'>Delete</a>|<a href='logo.php?logoID=26'>Edit</a></td>
                    <input type='hidden' name='partner' value='26'></input>
                    <td id='col4'><input type= 'radio' name='sponsor' value='4'/>
                </tr><tr class='details'>

                    <td id='col4'><img id='logos' src='../media/images/logo5.png'/></td>
                    <td id='col1'>Scotts</td>
                    <td id='col2'>http://www.scotts.com.mt/</td>
                    <td id='col3'><a href='delete.php?partnerID=27'>Delete</a>|<a href='logo.php?logoID=27'>Edit</a></td>
                    <input type='hidden' name='partner' value='27'></input>
                    <td id='col4'><input type= 'radio' name='sponsor' value='4'/>
                </tr><tr class='details'>

                    <td id='col4'><img id='logos' src='../media/images/logo4.png'/></td>
                    <td id='col1'>stop point</td>
                    <td id='col2'>http://www.stopshopmt.com/</td>
                    <td id='col3'><a href='delete.php?partnerID=28'>Delete</a>|<a href='logo.php?logoID=28'>Edit</a></td>
                    <input type='hidden' name='partner' value='28'></input>
                    <td id='col4'><input type= 'radio' name='sponsor' value='4'/>
                </tr><tr class='details'>

                    <td id='col4'><img id='logos' src='../media/images/logo6.png'/></td>
                    <td id='col1'>banif</td>
                    <td id='col2'>http://www.banif.com.mt/</td>
                    <td id='col3'><a href='delete.php?partnerID=29'>Delete</a>|<a href='logo.php?logoID=29'>Edit</a></td>
                    <input type='hidden' name='partner' value='29'></input>
                    <td id='col4'><input type= 'radio' name='sponsor' value='4'/>
                </tr><tr class='details'>

                    <td id='col4'><img id='logos' src='../media/images/logo8.png'/></td>
                    <td id='col1'>vassallo</td>
                    <td id='col2'>http://www.vassallogroupmalta.com/</td>
                    <td id='col3'><a href='delete.php?partnerID=30'>Delete</a>|<a href='logo.php?logoID=30'>Edit</a></td>
                    <input type='hidden' name='partner' value='30'></input>
                    <td id='col4'><input type= 'radio' name='sponsor' value='4'/>
                </tr><tr class='details'>

                    <td id='col4'><img id='logos' src='../media/images/logo11.png'/></td>
                    <td id='col1'>liquigas</td>
                    <td id='col2'>http://liquigasmalta.com/</td>
                    <td id='col3'><a href='delete.php?partnerID=31'>Delete</a>|<a href='logo.php?logoID=31'>Edit</a></td>
                    <input type='hidden' name='partner' value='31'></input>
                    <td id='col4'><input type= 'radio' name='sponsor' value='4'/>
                </tr><tr class='details'>

                    <td id='col4'><img id='logos' src='../media/images/logo10.png'/></td>
                    <td id='col1'>attardandco</td>
                    <td id='col2'>http://www.attardco.com/aboutus.html</td>
                    <td id='col3'><a href='delete.php?partnerID=32'>Delete</a>|<a href='logo.php?logoID=32'>Edit</a></td>
                    <input type='hidden' name='partner' value='32'></input>
                    <td id='col4'><input type= 'radio' name='sponsor' value='4'/>
                </tr><tr class='details'>

                    <td id='col4'><img id='logos' src='../media/images/logo9.png'/></td>
                    <td id='col1'>luxuriousM</td>
                    <td id='col2'>http://luxuriousm.com/</td>
                    <td id='col3'><a href='delete.php?partnerID=33'>Delete</a>|<a href='logo.php?logoID=33'>Edit</a></td>
                    <input type='hidden' name='partner' value='33'></input>
                    <td id='col4'><input type= 'radio' name='sponsor' value='4'/>
                </tr><tr class='details'>

                    <td id='col4'><img id='logos' src='../media/images/logo12.png'/></td>
                    <td id='col1'>garmin</td>
                    <td id='col2'>http://www.garminmalta.com/</td>
                    <td id='col3'><a href='delete.php?partnerID=34'>Delete</a>|<a href='logo.php?logoID=34'>Edit</a></td>
                    <input type='hidden' name='partner' value='34'></input>
                    <td id='col4'><input type= 'radio' name='sponsor' value='4'/>
                </tr><tr class='details' style='background-color: rgba(250, 0, 0, 0.5);'>

                    <td id='col4'><img id='logos' src='../media/images/mainsponsor1.png'/></td>
                    <td id='col1'>AFSignstudo</td>
                    <td id='col2'>http://www.afsignstudio.com/</td>
                    <td id='col3'><a href='delete.php?partnerID=41'>Delete</a>|<a href='logo.php?logoID=41'>Edit</a></td>
                    <input type='hidden' name='partner' value='41'></input>
                    <td id='col4'><input type= 'radio' name='sponsor' value='4'/>
                </tr></table>               
            <button id="newpartner" type="submit" name="save_partner_btn">Save Main Sponsor</button>
         </form>

标志
搭档
统一资源定位地址
行动
主赞助商
纯净的
http://www.pureconcepts.com.mt/
|
沃尔特
http://www.wuerth.com.mt/
|
马格里旋回
http://www.magricycles.com/
|
运动饮料
http://www.gsd.com.mt/
|
斯科茨
http://www.scotts.com.mt/
|
停止点
http://www.stopshopmt.com/
|
班尼弗银行
http://www.banif.com.mt/
|
瓦萨洛
http://www.vassallogroupmalta.com/
|
利基加斯
http://liquigasmalta.com/
|
阿塔丹科
http://www.attardco.com/aboutus.html
|
奢侈
http://luxuriousm.com/
|
加敏
http://www.garminmalta.com/
|
阿夫西诺
http://www.afsignstudio.com/
|
拯救主要赞助商
PHP部分

else if (isset($_POST['save_partner_btn'])) {
    $partner = (isset($_POST['partner']) ? $_POST['partner'] : null);
    $sponsor = $_POST['sponsor'];

    echo $partner ."<br>";
    echo $sponsor;
}
else if(isset($\u POST['save\u partner\u btn')){
$partner=(isset($\u POST['partner'])?$\u POST['partner']为空);
$赞助商=$_POST[“赞助商”];
echo$partner.“
”; echo$赞助商; }
目前的问题是,无论选择哪个单选按钮,回显值都是“41”(与上一个值相同)。我如何解决这个问题?

使用这个

<form action="" method="POST">
     <input type='hidden' name='partner' id='partner' value=''/>
      <table id='partnertable'>
            <tr id='head'>
                <th class='col4'>Logo</th>
                <th class='col1'>Partner</th>
                <th class='col2'>URL</th>
                <th class='col3'>Actions</th>
                <th class ='col4'>Main Sponsor</th>

            </tr><tr class='details'>
                <td class = 'col4'><img id='logos' src='../media/images/logo1.png'/></td>
                <td class='col1'>Pure</td>
                <td class='col2'>http://www.pureconcepts.com.mt/</td>
                <td class='col3'><a href='delete.php?partnerID=21'>Delete</a>|<a href='logo.php?logoID=21'>Edit</a></td>                   
                <td class='col4'><input type= 'radio' name='sponsor' value='4' onclick="addHiddenValue('21');"/>
            </tr><tr class='details'>

                <td class='col4'><img id='logos' src='../media/images/logo2.png'/></td>
                <td class='col1'>wuerth</td>
                <td class='col2'>http://www.wuerth.com.mt/</td>
                <td class='col3'><a href='delete.php?partnerID=22'>Delete</a>|<a href='logo.php?logoID=22'>Edit</a></td>
                <td class='col4'><input type= 'radio' name='sponsor' value='4' onclick="addHiddenValue('22')"/>      
            -----
            -----
            ----

并在javascript或jquery中更新其值。根据您的实现,当他们选择单选按钮时,这可能会起作用:

<form action="" method="POST">                
          <input type='hidden' name='sponsor' value='4'>
          <table id='partnertable'>
                <tr id='head'>
                    <th class='col4'>Logo</th>
                    <th class='col1'>Partner</th>
                    <th class='col2'>URL</th>
                    <th class='col3'>Actions</th>
                    <th class='col4'>Main Sponsor</th>

                </tr><tr class='details'>

                    <td class='col4'><img id='logos' src='../media/images/logo1.png'/></td>
                    <td class='col1'>Pure</td>
                    <td class='col2'>http://www.pureconcepts.com.mt/</td>
                    <td class='col3'><a href='delete.php?partnerID=21'>Delete</a>|<a href='logo.php?logoID=21'>Edit</a></td>
                     <td class='col4'><input type= 'radio' name='partner' value='21'/></td>
                </tr><tr class='details'>

                    <td class='col4'><img id='logos' src='../media/images/logo2.png'/></td>
                    <td class='col1'>wuerth</td>
                    <td class='col2'>http://www.wuerth.com.mt/</td>
                    <td class='col3'><a href='delete.php?partnerID=22'>Delete</a>|<a href='logo.php?logoID=22'>Edit</a></td>
                    <td class='col4'><input type= 'radio' name='partner' value='22'/></td>
                </tr><tr class='details'>

                    <td class='col4'><img id='logos' src='../media/images/logo3.png'/></td>
                    <td class='col1'>magri cycles</td>
                    <td class='col2'>http://www.magricycles.com/</td>
                    <td class='col3'><a href='delete.php?partnerID=23'>Delete</a>|<a href='logo.php?logoID=23'>Edit</a></td>
                    <td class='col4'><input type= 'radio' name='partner' value='23'/></td>
                </tr>
 .
 .
 .

标志
搭档
统一资源定位地址
行动
主赞助商
纯净的
http://www.pureconcepts.com.mt/
|
沃尔特
http://www.wuerth.com.mt/
|
马格里旋回
http://www.magricycles.com/
|
.
.
.

use多次使用隐藏字段合作伙伴,因此最后定义的值将被发布。您所有的
都标记为mysql。没有任何代码支持该问题,也不包含该问题的db模式。编辑:在你指出问题的相关性之前,它已经被删除。你还重复了很多HTML
id
s。这不好。@GeoffAtkins不仅仅是不好,它是不允许的,也不会被验证。重复的id会给你带来比你想象的更多的问题。
<form action="" method="POST">                
          <input type='hidden' name='sponsor' value='4'>
          <table id='partnertable'>
                <tr id='head'>
                    <th class='col4'>Logo</th>
                    <th class='col1'>Partner</th>
                    <th class='col2'>URL</th>
                    <th class='col3'>Actions</th>
                    <th class='col4'>Main Sponsor</th>

                </tr><tr class='details'>

                    <td class='col4'><img id='logos' src='../media/images/logo1.png'/></td>
                    <td class='col1'>Pure</td>
                    <td class='col2'>http://www.pureconcepts.com.mt/</td>
                    <td class='col3'><a href='delete.php?partnerID=21'>Delete</a>|<a href='logo.php?logoID=21'>Edit</a></td>
                     <td class='col4'><input type= 'radio' name='partner' value='21'/></td>
                </tr><tr class='details'>

                    <td class='col4'><img id='logos' src='../media/images/logo2.png'/></td>
                    <td class='col1'>wuerth</td>
                    <td class='col2'>http://www.wuerth.com.mt/</td>
                    <td class='col3'><a href='delete.php?partnerID=22'>Delete</a>|<a href='logo.php?logoID=22'>Edit</a></td>
                    <td class='col4'><input type= 'radio' name='partner' value='22'/></td>
                </tr><tr class='details'>

                    <td class='col4'><img id='logos' src='../media/images/logo3.png'/></td>
                    <td class='col1'>magri cycles</td>
                    <td class='col2'>http://www.magricycles.com/</td>
                    <td class='col3'><a href='delete.php?partnerID=23'>Delete</a>|<a href='logo.php?logoID=23'>Edit</a></td>
                    <td class='col4'><input type= 'radio' name='partner' value='23'/></td>
                </tr>
 .
 .
 .