PHP mysql_num_rows死亡错误 [英] PHP mysql_num_rows die error
本文介绍了PHP mysql_num_rows死亡错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想创建一个页面,用户可以在其中添加信息. 我已经创建了该页面,但是我真正的问题是向下的代码.
I want to create one page, where users add their informations.. I allready have that page created, but my real problem its down code..
我在那部分代码上有问题:
I have some kind of problem, with that part of code:
<?php
//Connect to DB
$db = mysql_connect("localhost","USER","PASS") or die("Database Error");
mysql_select_db("DB",$db);
//Get ID from request
$idstire = isset($_GET['idstire']) ? (int)$_GET['idstire'] : 0;
//Check id is valid
if($idstire > 0)
{
//Query the DB
$resource = mysql_query("SELECT * FROM stiri2 WHERE idstire = " . $idstire);
if($resource === false)
{
die("Eroare la conectarea cu baza de date");
}
if(mysql_num_rows($resource) == 0)
{
die("Se pare ca stirea nu mai exista, sau a fost stearsa. <a href='http://www.wanted-web.ro'>ACASA</a>");
}
$user = mysql_fetch_assoc($resource);
echo "
<div class='main-article-content'>
<h2 class='article-title'>asd</h2>
<div class='article-photo'>
<img src='" . $user['poza'] . "' class='setborder' alt='' />
</div>
<div class='article-controls'>
<div class='date'>
<div class='calendar-date'>" . $user['data'] . "</div>
</div>
<div class='right-side'>
<div class='colored'>
<a href='' class='icon-link'><span class='icon-text'></span>Printeaza articol</a>
<a href='#' class='icon-link'><span class='icon-text'></span>Trimite prietenilor</a>
</div>
<div>
<a href='#' class='icon-link'><span class='icon-text'></span>de Cristian Cosmin D.</a>
<a href='#' class='icon-link'><span class='icon-text'></span>39 comentarii</a>
</div>
</div>
<div class='clear-float'></div>
</div>
<div class='shortcode-content'>
<p>" . $user['nume'] . " , " . $user['prenume'] . " , " . $user['varsta'] . " , " . $user['localitatea'] . "</p>
</div>
</div>
";
}
$query = "UPDATE stiri2 SET accesari = accesari + 1 WHERE idstire=\"" . $idstire . "\"";
$result = mysql_query($query) OR die(mysql_error());
?>
从这里向我显示错误:
if(mysql_num_rows($resource) == 0)
{
die("Se pare ca stirea nu mai exista, sau a fost stearsa. <a href='http://www.wanted-web.ro'>ACASA</a>");
}
我真的不明白为什么!?
I really dont understand why!?
有人可以解释我吗? 谢谢!
Can someone explain me? Thank you!
推荐答案
mysql_query应该具有第二个参数作为连接,在您的情况下为$ db
mysql_query should have the second parameter as the connection which is in your case $db
$resource = mysql_query("SELECT * FROM stiri2 WHERE idstire = " . $idstire,$db);
如果这也行不通,请使用mysql_error知道确切的错误
if this also not works then use mysql_error to know the exact error
$row=mysql_num_rows($resource);
if($row)
{
}
else
{
mysql_error();
}
这将告诉您mysql_num_rows中是否有问题
this will show you if there is problwm in mysql_num_rows
这篇关于PHP mysql_num_rows死亡错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文