查询未在php中运行

时间:2016-10-06 13:41:14

标签: php mysql web wamp

您好,我正在尝试在PHP中创建一个屏幕。 我在其中选择场景并相应地显示屏幕。 但我陷入一个简单的问题,我的简单选择查询不起作用

$deptQuery = "Select * from mcb_department";
echo mysql_real_escape_string($deptQuery);
mysql_query($deptQuery) or die("adfasdf");

在相同的代码中,如果更改表名,它只是工作正常,此表也在db中创建,并且我已经共享了相同的名称。 这是我的完整代码。

<?php       
    include "include/conn.php";
    include "include/session.php";

    if(isset($_SESSION['logged_user']) && $_SESSION['logged_user'] != '99999'){
        header('location: login.php');
    }

    $query = mysql_query("select curdate() as todayDate");  
    $show = mysql_fetch_array($query);  
    if(isset($show)){                                 
        $todayDate=  $show['todayDate'];
    }

    $group[] = array();
?>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta Content="no-cache, no-store, must-revalidate" http-Equiv="Cache-Control" />
<meta Content="no-cache" http-Equiv="Pragma" />
<meta Content="0" http-Equiv="Expires" />

    <link href="styles/style.css" type="text/css" rel="stylesheet" />
    <link href="styles/popupstyle.css" type="text/css" rel="stylesheet" />   
    <link href="styles/ts.css" type="text/css" rel="stylesheet" />
    <link href="styles/calendar.css" type="text/css" rel="stylesheet" />         
      <style>
table {
    font-family: arial;
    border-collapse: collapse;
    width: 100%;
    font-size: 11px;
}

td, th {
    border: 1px solid #dddddd;
    text-align: left;
    padding: 3px;
}

tr:nth-child(even) {
    background-color: #dddddd;
}
</style>
</head> 
<body >

</body>

    <select id='select_opt'>
        <option> Select Assigment </option>
        <option value="1"> assign quiz to all Employees </option>
        <option value="2"> assign quiz to Sapcific Group </option>
        <option value="3"> assign quiz to Sapcific Department </option>
        <option value="4"> assign quiz to Sapcific Employee </option>
    </select>

    <!-- all Users -->

    <div id='allUsers' style='margin-left:20px; margin-top: 20px;  width: 50%; height:100px; display: none;' >
        <form action="" mathod="post">
        <select>
            <option value=""> select Quiz</option>
        </select>
        <input type="submit"  >
        </form>
    </div>

    <!-- group -->

    <div id='group' style='margin-left:20px; margin-top: 20px;  width: 50%; height:100px; display: none;' >

        <form action='group_assigment.php' mathod="post">
        <table>
        <tr>
          <th>All <input type="checkbox"> </th>
          <th>Group Name</th>
          <th>Group Code</th>
        </tr>
         <?php  
               $group[] = array();
               $groupQuery = "Select * from mcb_groups";
               $query = mysql_query($groupQuery);
            ?>
        <tr>
            <?php  if($query){
                   while($group = mysql_fetch_array($query)){
                ?>
         <td><input type="checkbox" value="<?php echo $group['group_name']; ?>"></td>
          <td><?php echo $group['group_name']; ?></td>
          <td><?php echo $group['group_code']; ?></td>
        </tr>
            <?php }

                   }  else{ echo "";} ?>
        </table>

            </form>

    </div>

    <!-- 
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    department 
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    -->
 <div id='Department' style='margin-left:20px; margin-top: 20px;  width: 50%; height:100px; display: none;' >

   <form action='group_assigment.php' mathod="post">

       <table>
           <tr>
             <th>all <input type="checkbox"> </th>
             <th>name</th>
             <th>code</th>
             <th>group</th>
           </tr>
           <tr>
               <?php
                    $deptQuery = "Select * from mcb_department";
                    echo mysql_real_escape_string($deptQuery);
                    mysql_query($deptQuery);
               ?>
               <td><input type="checkbox"></td>
               <td>code</td>
               <td>name</td>
               <td>group</td>
           </tr>

         </table>
        <input type="submit" >
        </form>
    </div>

    <!-- 
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
        Employee 
    @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
    -->    

        <div id='employee' style='margin-left:20px; margin-top: 20px;  width: 50%; height:100px; display: none;' >
         <form action="" mathod="post">
            <label>employee id : </label><input type="text" >
            <input type="submit" >
         </form>
    </div>


<script language="javascript" type="text/javascript">
 var elem = document.getElementById("select_opt");
            elem.onchange = function(){

                            console.log("yes i am running");
                            if( document.getElementById("select_opt").value == "1" ){

                                document.getElementById("allUsers").style.display = "Block";
                                document.getElementById("group").style.display = "none";
                                document.getElementById("Department").style.display = "none";
                                document.getElementById("employee").style.display = "none";

                            }
                            else if( document.getElementById("select_opt").value == "2" ){

                                document.getElementById("group").style.display = "Block";
                                document.getElementById("allUsers").style.display = "none";
                                document.getElementById("Department").style.display = "none";
                                document.getElementById("employee").style.display = "none";

                            }
                            else if( document.getElementById("select_opt").value == "3" ){

                                document.getElementById("Department").style.display = "block";
                                document.getElementById("group").style.display = "none";
                                document.getElementById("allUsers").style.display = "none";
                                document.getElementById("employee").style.display = "none";



                            }
                            else if( document.getElementById("select_opt").value == "4" ){

                                document.getElementById("employee").style.display = "block";
                                document.getElementById("Department").style.display = "none";
                                document.getElementById("group").style.display = "none";
                                document.getElementById("allUsers").style.display = "none";
                            }

                            else{


                            }



            };
 </script> 

</

HTML&GT;

方面, Shafee jan

1 个答案:

答案 0 :(得分:1)

  

在相同的代码中,如果更改表名,它就可以正常工作

然后我会确保您已连接到正确的数据库。对于开发人员而言,在不同的MySQL实例上或者在不同模式名称下的同一实例上拥有多个版本的数据库,这是非常常见的。然后他们混淆了,当他们的应用程序连接到不同的数据库时,使用MySQL Workbench连接到一个数据库。

我建议您暂时向页面添加查询以运行_ttoi(),然后将该查询的结果转储到日志中,以确认数据库中存在SHOW TABLES表您的PHP脚本已连接到。

mcb_department

您的错误检查在哪里?每次运行查询时都需要检查$deptQuery = "Select * from mcb_department"; echo mysql_real_escape_string($deptQuery); mysql_query($deptQuery); 的返回值,因此如果出现问题,请将错误消息输出到日志中。只有这样才能开始解决其中的一些问题。

mysql_query()

PS:一些评论者建议$result = mysql_query($deptQuery); if (!$result) { trigger_error("Error in file " . __FILE__ . " near line " . __LINE__ . " for query $deptQuery: " . mysql_error()); die("Database error"); } 函数被弃用是真的,但可能与你的问题无关。

,当你说API工作时,专注于API的人们就是迂腐