我发布了代码和结果,可能有人可以提供帮助..
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!
我直接尝试查询,我找到了我想要的一行,为什么这里不去? 我现在正在进行一些测试。
所有代码 - &gt;
<?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>
答案 0 :(得分:1)
我在您的代码中直接看到的一些问题。
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!';
}
}
?>
答案 1 :(得分:-1)
问题是我使用mysql_query而不是mysqli_query。