drrkgbm6851 2014-08-30 21:03
浏览 112
已采纳

继续收到通知:未定义的索引:无论我做什么

I am trying to fill a table in my database from a drop down menu which I populated from another table from my database. The problem is that whenever I submit my query, it gives me the same error "Notice: Undefined index:" and won't fill the table. I am new to coding, so please be gentle. This is the part for populating the drop down menu

<?php
@mysql_connect("localhost", "root","") or die(mysql_error());
mysql_select_db("motocikli") or die(mysql_error());

$query = "SELECT kategorija_ime FROM kategorija";
$result = mysql_query($query) or die(mysql_error()."[".$query."]");
?>

<select name="kateg">
<?php 
while ($row = mysql_fetch_array($result))
{
    echo "<option value='".$row['kategorija_ime']."'>'".$row['kategorija_ime']."'</option>";
}
?>        
</select>

 <form action="insert.php" method="post">
 <input type="submit">
</form>

And this is the insert.php

<?php

$dsn = 'mysql:dbname=motocikli;host=127.0.0.1';
$user = 'root';
$password = '';
$pdo = new \PDO($dsn, $user, $password);



function unesiPoruku($kateg)
{
    global $pdo;
    $upit = $pdo->prepare("INSERT INTO test (kateg) VALUES (:kateg)");
    $upit->bindParam('kateg',$kateg);

    $upit->execute();
}

$kateg = $_REQUEST['kateg'];
unesiPoruku($kateg);

?> 

The error is showing for $kateg = $_REQUEST['kateg'];, the 'kateg' tag.

  • 写回答

1条回答 默认 最新

  • dr2898 2014-08-30 21:05
    关注

    Your select box needs to be inside the form so that the value is posted properly to the server

    ie.

    <form action="insert.php" method="post">
          <select name="kateg">
          <?php 
             while ($row = mysql_fetch_array($result))
             {
                 echo "<option value='".$row['kategorija_ime']."'>'".$row['kategorija_ime']."'</option>";
             }
          ?>        
          </select>
    
          <input type="submit">
    </form>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器