2016-08-01 268 views
0

我张贴代码和结果,可能有些人可以帮助..PHP查询返回NULL不可能

if (isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] > 0) 
       { 
        $id = $_GET['id']; 
        echo $login_session_id.$id; 
        include('config.php'); 
        set_time_limit(59); 
        $resultEdit = mysql_query($db,"select * from Rubrica where ID_Utente = '$login_session_id' AND ID_Dispositivo='$id' ")or die(mysql_error());; 
        if (!$resultEdit) { 
         die('Invalid query: ' . mysql_error()); 
        } 
        if(mysqli_num_rows($resultEdit)==1) 
        { 
         echo 'fatto'; 
         while($row = $resultEdit ->fetch_assoc()) 
         { 
         echo 'fatto'; 
         $id=$row['ID_Dispositivo']; 
         $Username = $row['Username']; 
         $Email= $row['Email']; 
         $Cellulare= $row['Mobile']; 
         $Casa= $row['Home']; 
         $Lavoro= $row['Work']; 
         renderForm($id, $Username, $Email,$Cellulare,$Casa,$Lavoro,$error); 
         } 
        } 
        else 
        { 
         echo "No results!"; 
        } 
       } 
       else 
       { 
        echo 'Error!'; 
       } 

      } 

结果页面:

21 18 <---Correct! 

我直接尝试查询,我发现一个排我想要什么,为什么这里不去? 我现在谈论的时候,但我做了一些测试。

全部代码 - >

<?php 
 
    include('session.php'); 
 
?> 
 

 
<!DOCTYPE html> 
 
<html> 
 
<head> 
 
<title>ControlPannel</title> 
 
<!-- jQuery--> 
 
<script src="/web/js/jquery.min.js"></script> 
 
<!-- Custom Theme files --> 
 
<!--theme-style--> 
 
<link href="/web/css/style.css" rel="stylesheet" type="text/css" media="all" /> \t 
 
<!--//theme-style--> 
 
<meta name="viewport" content="width=device-width, initial-scale=1"> 
 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
 
<meta name="keywords" content="Panello di controllo applicazione" /> 
 
<script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script> 
 
<!--fonts--> 
 
<link rel="icon" href="/web/images/logoB.png"> 
 
<!--//fonts--> 
 
</head> 
 
<body> 
 
\t <div class="header"> 
 
\t <!----> 
 
\t \t <div class="header-left"> 
 
\t \t \t <div class="logo"> 
 
\t \t \t \t <a href="index.html"><img src="/web/images/logo.png" alt=""></a> 
 
\t \t \t </div> 
 
\t \t \t <div class="top-nav"> 
 
\t \t \t \t <ul > 
 
\t \t \t \t \t <li><h1>Welcome <?php echo $user_check_email; ?></h1> </li> 
 
\t \t \t \t \t <li class="active" ><a href="" >RUBRICA</a></li> 
 
\t \t \t \t \t <li><a href="Promemoria.php" class="black" > PROMEMORIA</a></li> \t 
 
\t \t \t \t \t <li><a href="Sos.php" class="black1"> SOS</a></li> 
 
\t \t \t \t \t <li><a href="imp.php" class="black2" > IMPOSTAZIONI</a></li> 
 
\t \t \t \t \t <li><a href="LogOut.php" class="black2" > LOGOUT</a></li> 
 
\t \t \t \t </ul> 
 
\t \t \t </div> 
 
\t \t \t <p class="footer-class">Template by <a href="" target="_blank">42Studios</a> </p> 
 
\t \t </div> 
 
\t \t <!----> 
 
\t \t <!----> 
 
\t \t <div class="header-top"> 
 
\t \t \t <div class="logo-in"> 
 
\t \t \t \t <a href="index.html"><img src="/web/images/logo.png" alt=""></a> 
 
\t \t \t </div> 
 
\t \t \t <div class="top-nav-in"> 
 
\t \t \t <span class="menu"><img src="/web/images/menu.png" alt=""> </span> 
 
\t \t \t \t <ul > 
 
\t \t \t \t \t <li class="active" ><a href="" >RUBRICA</a></li> 
 
\t \t \t \t \t <li><a href="Promemoria.php" class="black" > PROMEMORIA</a></li> \t 
 
\t \t \t \t \t <li><a href="Sos.php" class="black1"> SOS</a></li> 
 
\t \t \t \t \t <li><a href="imp.php" class="black2" > IMPOSTAZIONI</a></li> 
 
\t \t \t \t \t <li><a href="LogOut.php" class="black2" > LOGOUT</a></li> 
 
\t \t \t \t </ul> 
 
\t \t \t \t <script> 
 
\t \t \t \t \t $("span.menu").click(function(){ 
 
\t \t \t \t \t \t $(".top-nav-in ul").slideToggle(500, function(){ 
 
\t \t \t \t \t \t }); 
 
\t \t \t \t \t }); 
 
\t \t \t </script> 
 

 
\t \t \t </div> 
 
\t \t \t <div class="clear"> </div> 
 
\t \t </div> 
 
\t \t \t <!----> 
 
\t \t <div class="content"> 
 
\t \t \t <div class="Block"> 
 
\t \t \t \t <?php 
 

 
\t \t \t \t \t 
 
\t \t \t \t \t function renderForm($id, $Username, $Email,$Cellulare,$Casa,$Lavoro,$error) 
 
\t \t \t \t \t { 
 

 
\t \t \t \t \t \t if ($error != '') 
 
\t \t \t \t \t \t { 
 
\t \t \t \t \t \t \t echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>'; 
 
\t \t \t \t \t \t } 
 
\t \t \t \t \t ?> 
 
\t \t \t \t <form action="" method="post"> 
 
\t \t \t \t \t <input type="hidden" name="id" value="<?php echo $id; ?>"/> 
 
\t \t \t \t \t <div> 
 
\t \t \t \t \t \t <p><strong>ID:</strong> <?php echo $id; ?></p> 
 
\t \t \t \t \t \t <strong>Username: *</strong> <input type="text" name="Username" value="<?php echo $Username; ?>" /><br/> 
 
\t \t \t \t \t \t <strong>Email: *</strong> <input type="text" name="Email" value="<?php echo $Email; ?>" /><br/> 
 
\t \t \t \t \t \t <strong>Cellulare: *</strong> <input type="text" name="Mobile" value="<?php echo $Cellulare; ?>" /><br/> 
 
\t \t \t \t \t \t <strong>Casa: *</strong> <input type="text" name="Home" value="<?php echo $Casa; ?>" /><br/> 
 
\t \t \t \t \t \t <strong>Lavoro: *</strong> <input type="text" name="Work" value="<?php echo $Lavoro; ?>" /><br/> 
 
\t \t \t \t \t \t <p>* Required</p> 
 
\t \t \t \t \t \t \t <input type="submit" name="submit" value="Submit"> 
 
\t \t \t \t \t </div> 
 
\t \t \t \t </form> 
 
\t \t \t \t <?php 
 
\t \t \t } 
 
\t \t \t include('config.php'); 
 
\t \t \t if (isset($_POST['submit'])) 
 
\t \t \t \t { 
 
\t \t \t \t \t echo '1'; 
 
\t \t \t \t \t if (is_numeric($_POST['id'])) 
 
\t \t \t \t \t { 
 
\t \t \t \t \t \t $id = $_POST['id']; 
 
\t \t \t \t \t \t $Username = mysql_real_escape_string(htmlspecialchars($_POST['Username'])); 
 
\t \t \t \t \t \t $Email = mysql_real_escape_string(htmlspecialchars($_POST['Email'])); 
 
\t \t \t \t \t \t $Cellulare = mysql_real_escape_string(htmlspecialchars($_POST['Mobile'])); 
 
\t \t \t \t \t \t $Casa= mysql_real_escape_string(htmlspecialchars($_POST['Home'])); 
 
\t \t \t \t \t \t $Lavoro = mysql_real_escape_string(htmlspecialchars($_POST['Work'])); 
 
\t \t \t \t \t \t if ($Username == '') 
 
\t \t \t \t \t \t \t { 
 
\t \t \t \t \t \t \t \t $error = 'ERROR: Please fill in all required fields!'; 
 
\t \t \t \t \t \t \t \t renderForm($id, $Username, $Email,$Cellulare,$Casa,$Lavoro,$error); 
 
\t \t \t \t \t \t \t } 
 
\t \t \t \t \t \t \t else 
 
\t \t \t \t \t \t \t { 
 
\t \t \t \t \t \t \t \t // save the data to the databaseRubrica where ID_Utente = '$login_session_id' 
 
\t \t \t \t \t \t \t \t mysql_query($db,"UPDATE Rubrica SET Username='$Username',Mobile='$Cellulare',Home='$Casa',Work='$Lavoro',Email='$Email' WHERE ID_Utente = '$login_session_id' AND ID_Dispositivo='$id'")or die(mysql_error()); 
 
\t \t \t \t \t \t \t \t header("Location: RUBRICA.php"); 
 
\t \t \t \t \t \t \t } 
 
\t \t \t \t \t } 
 
\t \t \t \t \t else 
 
\t \t \t \t \t { 
 
\t \t \t \t \t \t echo 'Error!'; 
 
\t \t \t \t \t } 
 
\t \t \t \t } 
 
\t \t \t \t else 
 
\t \t \t \t { \t 
 
\t \t \t \t \t include('config.php'); 
 
\t \t \t \t \t if ((isset($_GET['id'])) && (is_numeric($_GET['id'])) && ($_GET['id'] > 0)) 
 
\t \t \t \t \t { 
 
\t \t \t \t \t \t $id = $_GET['id']; 
 
\t \t \t \t \t \t echo $login_session_id.$id; 
 
\t \t \t \t \t \t set_time_limit(59); 
 
\t \t \t \t \t \t $resultEdit = mysql_query($db,"select * from Rubrica where ID_Utente = '$login_session_id' AND ID_Dispositivo='$id' ")or die(mysql_error());; 
 
\t \t \t \t \t \t if (!$resultEdit) { 
 
\t \t \t \t \t \t \t die('Invalid query: ' . mysql_error()); 
 
\t \t \t \t \t \t } 
 
\t \t \t \t \t \t if(mysqli_num_rows($resultEdit)==1) 
 
\t \t \t \t \t \t { 
 
\t \t \t \t \t \t \t echo 'fatto'; 
 
\t \t \t \t \t \t \t while($row = $resultEdit ->fetch_assoc()) 
 
\t \t \t \t \t \t \t { 
 
\t \t \t \t \t \t \t echo 'fatto'; 
 
\t \t \t \t \t \t \t $id=$row['ID_Dispositivo']; 
 
\t \t \t \t \t \t \t $Username = $row['Username']; 
 
\t \t \t \t \t \t \t $Email= $row['Email']; 
 
\t \t \t \t \t \t \t $Cellulare= $row['Mobile']; 
 
\t \t \t \t \t \t \t $Casa= $row['Home']; 
 
\t \t \t \t \t \t \t $Lavoro= $row['Work']; 
 
\t \t \t \t \t \t \t renderForm($id, $Username, $Email,$Cellulare,$Casa,$Lavoro,$error); 
 
\t \t \t \t \t \t \t } 
 
\t \t \t \t \t \t } 
 
\t \t \t \t \t \t else 
 
\t \t \t \t \t \t { 
 
\t \t \t \t \t \t \t echo "No results!"; 
 
\t \t \t \t \t \t } 
 
\t \t \t \t \t } 
 
\t \t \t \t \t else 
 
\t \t \t \t \t { 
 
\t \t \t \t \t \t echo 'Error!'; 
 
\t \t \t \t \t } 
 

 
\t \t \t \t } 
 
?> 
 
\t \t \t \t ///query 
 
\t \t \t \t <div id="risultato"></div> 
 
\t \t \t </div> 
 
\t \t \t 
 
\t \t </div> 
 
\t \t <div class="clear"> </div> 
 
\t \t <p class="footer-class-in">Copyright © 2015 Template by <a href="" target="_blank">42Studios</a> </p> 
 
\t </div> 
 
</body> 
 
</html> 
 
\t \t \t
数据 enter image description here enter image description here 选择返回NULL

+0

您能解释一下您面临的问题吗? – Akshay

+0

选择返回nothigs –

+0

不要忘了接受的答案,如果它帮助你:) – Akshay

回答

1

一些问题,我直接看到你的代码。

1)。所有包含文件应基本上位于文件的顶部。所有包含和所需的文件应始终位于顶部。 2)。您的如果陈述不正确。您应该根据您的情况使用()。 3)。该功能mysql_query接受参数以这样的方式 -

mysql_query(query, connection) 

因此,最终的代码应该是这样的: -

<?php 
include('config.php'); 
if ((isset($_GET['id'])) && (is_numeric($_GET['id'])) && ($_GET['id'] > 0)) 
       { 
        $id = $_GET['id']; 
        echo $login_session_id.$id; 
        set_time_limit(59); 
        $resultEdit = mysql_query("select * from Rubrica where ID_Utente = '$login_session_id' AND ID_Dispositivo='$id' ", $db)or die(mysql_error());; 
        if (!$resultEdit) { 
         die('Invalid query: ' . mysql_error()); 
        } 
        if(mysqli_num_rows($resultEdit)==1) 
        { 
         echo 'fatto'; 
         while($row = $resultEdit ->fetch_assoc()) 
         { 
          echo 'fatto'; 
          $id=$row['ID_Dispositivo']; 
          $Username = $row['Username']; 
          $Email= $row['Email']; 
          $Cellulare= $row['Mobile']; 
          $Casa= $row['Home']; 
          $Lavoro= $row['Work']; 
          renderForm($id, $Username, $Email,$Cellulare,$Casa,$Lavoro,$error); 
         } 
        } 
        else 
        { 
         echo "No results!"; 
        } 
       } 
       else 
       { 
        echo 'Error!'; 
       } 

      } 

      ?> 
+0

没了什么变化 –

+0

我只是尝试这样做 –

+0

OK等待我添加的所有代码@Akshay –

-1

问题是我使用的mysql_query代替mysqli_query。