dqdes60666 2018-06-15 07:59
浏览 87

注意错误:未定义的索引:

I have to fill a dropdown select with values from a database, and then i have to check if the value is correct with a javascript function which i have already done.

I have two columns, one with id identifiers and the other one with names. The selection "comune" has to return to javascript function the IDs but the names have to be printed in the selection. This is the code I've written so far.

    <?php ?>
<html>
<head>
</head>
<body>

<?php
require "connessione.php";
ini_set('display_errors', 1);

?>


<form name="myForm" action="javascript:funzione_visualizzazione();">

               <select name="comune">
                <?php
                $sql = "SELECT * FROM table_3"; 
                $query = mysqli_query($connessione,$sql) or die("MySQL error: " . mysqli_error($connessione) . "<hr>
Query: $query");


        while($row=mysqli_fetch_array($query)){

                $nome_comuni = $row["nome_comuni"];

                $id_comuni = $row["id_comuni"];

                         ?>
                <option value="<?php echo $id_comuni?>"><?php echo $nome_comuni?></option>

                <?php
        }
                     ?> 



        </select>

        <select name="fabbisogno_totale">
                <option value="5"> 5t </option>
                <option value="15"> 15t </option>
                <option value="20"> 20t </option>
                <option value="25"> 25t </option>
                <option value="30"> 30t </option>
        </select>

        <input name="fabbisogno_coperto" type="number" value="    " size="40" maxlength="25" />

        <script language="javascript">
        function funzione_visualizzazione(){

            if(document.myForm.comune.value != null && document.myForm.fabbisogno_totale.value != null && document.myForm.fabbisogno_coperto.value != null){
                //call the php page for elaborate datas
            }
            else 
                alert("inserire dati in tutti i campi");

        }


        </script>




</form>

</body>
</html>

The code is properly connected to the database because it prints "connected to mySQL".

I'm testing on xampp because the real database doesnt work right now.

UPDATE: i resolved the error i had before but now i'm getting notice errors

Undefined index: nome_comuni in <b>C:\xampp\htdocs\selezioni.php</b> on line <b>24</b><br />

on the line 24 i got $nome_comuni = $row["nome_comuni"]; and the same error occurs at the line 26

The drop down select has as many empty possible selection as there are on the database but it doesn't show anything. for example, if i have 7 rows in the database the dropdown selection shows 7 empty rows, how can i get the selections be showed?

this is my database "id_comuni" "id_province" "nome_comuni

One more question, if I leave the selection blank, does it return null or an empy string?

Sorry for my english but i'm italian, if there are grammatical errors please point them out.

  • 写回答

1条回答 默认 最新

  • donglu4633 2018-06-15 08:18
    关注

    For what I can see, you are storing your query result in a var named $cicle, but trying to access to them with var named $row.

    Something like that should do the trick. (if it was what you needed)

    Also, try to be more clear asking your question, as you never provided a proper state of what you really need, and what's not working as intend

    <?php
       $sql = "SELECT * FROM comuni_new"; 
       $query = mysql_query($connessione,$sql) or die("MySQL error: " . 
       mysql_error($connessione) . "<hr>
    Query: $query");
       while($row = mysql_fetch_row($query)){
          echo '<option value=". $row[\'id_comuni\']">$row[\'nome_comuni\']</option> '
       }
    ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用