PHP 查询返回 null !不可能

标签 php mysql sql

我发布了代码和结果,也许有人可以提供帮助..

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" />	
<!--//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>
			
数据 enter image description here enter image description here 选择返回 null

最佳答案

我直接在您的代码中看到的一些问题。

1).所有包含文件基本上都应该位于文件的顶部。所有包含和必需的文件应始终位于顶部。

2).您的 if 语句不正确。您应该使用 () 来满足您的条件。

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

            }

            ?>

关于PHP 查询返回 null !不可能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38704063/

相关文章:

MySQL 错误 : This type of clause previously parsed.(SELECT 附近)

PHP流程逻辑问题

php - 如何在 PHP 中回显不同的计数?

php - 在php中插入数据时出错

mysql - RoR 监视经常更新的表中的更改

php - 选择查询不起作用

mysql - 优化 'GROUP BY'-查询,消除 'Using where; Using temporary; Using filesort'

sql - 根据它在另一个表 psql 中的可用性对一个表的结果进行排序

php - &lt;input type=submit/> 是否在幕后使用了 javascript

php - 字母数字数组排序(警告 : spaces as a thousands separator in numbers)