简体   繁体   English

PHP查询返回null!不可能

[英]PHP Query return null !impossible

i post the code and the result, may some one can help.. 我发布代码和结果,也许有人可以帮忙..

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!';
                }

            }

result page: 结果页:

21 18 <---Correct!

i try directly the query and i found one row what i want, why here don't go? 我直接尝试查询,却发现我想要的一行,为什么这里不走? i now about the while but i do some test. 我现在大约有一段时间,但我做了一些测试。

All Code -> 所有代码->

 <?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" /> <!--//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> <div class="header"> <!----> <div class="header-left"> <div class="logo"> <a href="index.html"><img src="/web/images/logo.png" alt=""></a> </div> <div class="top-nav"> <ul > <li><h1>Welcome <?php echo $user_check_email; ?></h1> </li> <li class="active" ><a href="" >RUBRICA</a></li> <li><a href="Promemoria.php" class="black" > PROMEMORIA</a></li> <li><a href="Sos.php" class="black1"> SOS</a></li> <li><a href="imp.php" class="black2" > IMPOSTAZIONI</a></li> <li><a href="LogOut.php" class="black2" > LOGOUT</a></li> </ul> </div> <p class="footer-class">Template by <a href="" target="_blank">42Studios</a> </p> </div> <!----> <!----> <div class="header-top"> <div class="logo-in"> <a href="index.html"><img src="/web/images/logo.png" alt=""></a> </div> <div class="top-nav-in"> <span class="menu"><img src="/web/images/menu.png" alt=""> </span> <ul > <li class="active" ><a href="" >RUBRICA</a></li> <li><a href="Promemoria.php" class="black" > PROMEMORIA</a></li> <li><a href="Sos.php" class="black1"> SOS</a></li> <li><a href="imp.php" class="black2" > IMPOSTAZIONI</a></li> <li><a href="LogOut.php" class="black2" > LOGOUT</a></li> </ul> <script> $("span.menu").click(function(){ $(".top-nav-in ul").slideToggle(500, function(){ }); }); </script> </div> <div class="clear"> </div> </div> <!----> <div class="content"> <div class="Block"> <?php function renderForm($id, $Username, $Email,$Cellulare,$Casa,$Lavoro,$error) { if ($error != '') { echo '<div style="padding:4px; border:1px solid red; color:red;">'.$error.'</div>'; } ?> <form action="" method="post"> <input type="hidden" name="id" value="<?php echo $id; ?>"/> <div> <p><strong>ID:</strong> <?php echo $id; ?></p> <strong>Username: *</strong> <input type="text" name="Username" value="<?php echo $Username; ?>" /><br/> <strong>Email: *</strong> <input type="text" name="Email" value="<?php echo $Email; ?>" /><br/> <strong>Cellulare: *</strong> <input type="text" name="Mobile" value="<?php echo $Cellulare; ?>" /><br/> <strong>Casa: *</strong> <input type="text" name="Home" value="<?php echo $Casa; ?>" /><br/> <strong>Lavoro: *</strong> <input type="text" name="Work" value="<?php echo $Lavoro; ?>" /><br/> <p>* Required</p> <input type="submit" name="submit" value="Submit"> </div> </form> <?php } include('config.php'); if (isset($_POST['submit'])) { echo '1'; if (is_numeric($_POST['id'])) { $id = $_POST['id']; $Username = mysql_real_escape_string(htmlspecialchars($_POST['Username'])); $Email = mysql_real_escape_string(htmlspecialchars($_POST['Email'])); $Cellulare = mysql_real_escape_string(htmlspecialchars($_POST['Mobile'])); $Casa= mysql_real_escape_string(htmlspecialchars($_POST['Home'])); $Lavoro = mysql_real_escape_string(htmlspecialchars($_POST['Work'])); if ($Username == '') { $error = 'ERROR: Please fill in all required fields!'; renderForm($id, $Username, $Email,$Cellulare,$Casa,$Lavoro,$error); } else { // save the data to the databaseRubrica where ID_Utente = '$login_session_id' 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()); header("Location: RUBRICA.php"); } } else { echo 'Error!'; } } else { 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($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!'; } } ?> ///query <div id="risultato"></div> </div> </div> <div class="clear"> </div> <p class="footer-class-in">Copyright © 2015 Template by <a href="" target="_blank">42Studios</a> </p> </div> </body> </html> 
Data 数据 在此处输入图片说明 在此处输入图片说明 the select return null 选择返回null

Some issues that I see directly in your code. 我直接在您的代码中看到的一些问题。

1). 1)。 All include files should basically be on top of your file. 基本上,所有包含文件都应位于文件顶部。 All include and required files should always be at top. 所有包含文件和必需文件应始终位于顶部。

2). 2)。 Your if statement is not correct. 您的if陈述不正确。 You should use () for your conditions. 您应该使用()作为条件。

3). 3)。 The function mysql_query accepts parameters in this way :- mysql_query函数以这种方式接受参数:

mysql_query(query, connection)

So your final code should be something like this :- 所以您的最终代码应该是这样的:

<?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!';
                }

            }

            ?>

问题是我使用mysql_query代替mysqli_query。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM