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

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

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.

图片转代码服务由CSDN问答提供 功能建议

我试图从我的数据库中的另一个表填充的下拉菜单中填充数据库中的表 。 问题是每当我提交我的查询时,它都会给我相同的错误“通知:未定义的索引:”并且不会填充表格。 我是编码的新手,所以请保持温和。 这是填充下拉菜单的部分

 &lt;?php 
 @ mysql_connect(“localhost”,“  root“,”“)或die(mysql_error()); 
mysql_select_db(”motocikli“)或die(mysql_error()); 
 
 $ query =”SELECT kategorija_ime FROM kategorija“; 
 $ result = mysql_query(  $ query)或die(mysql_error()。“[”。$ query。“]”); 
?&gt; 
 
&lt; select name =“kateg”&gt; 
&lt;?php 
while($ row  = mysql_fetch_array($ result))
 {
 echo“&lt; option value ='”。$ row ['kategorija_ime']。“'&gt;'”。$ row ['kategorija_ime']。“'&lt; / 选项&gt;“中; \ N} 
&GT?;  
&lt; / select&gt; 
 
&lt; form action =“insert.php”method =“post”&gt; 
&lt; input type =“submit”&gt; 
&lt; / form&gt; 
   
 
 

这是insert.php

 &lt;?php 
 
 $ dsn ='mysql:dbname = motocikli  ; host = 127.0.0.1'; 
 $ user ='root'; 
 $ password =''; 
 $ pdo = new \ PDO($ dsn,$ user,$ password); 
 
 
  
 
函数unesiPoruku($ kateg)
 {
 
 
 
 
 
全局$ pdo; 
 $ upit = $ pdo-&gt; prepare(“INSERT INTO test(kateg)VALUES(:kateg)”); 
 $ upit-&gt;  bindParam('kateg',$ kateg); 
 
 $ upit-&gt; execute(); 
} 
 
 $ kateg = $ _REQUEST ['kateg']; 
unesiPoruku($ kateg); 
  
&GT?;  
   
 
 

错误显示为$ kateg = $ _REQUEST ['kateg'] ;,'kateg'标记。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

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>
    
    已采纳该答案
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题