douyan1921 2013-08-24 12:21
浏览 39
已采纳

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());
?>

It's show me error from here:

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!

  • 写回答

3条回答 默认 最新

  • douyingzhan5905 2013-08-24 12:35
    关注

    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);
    

    if this also not works then use mysql_error to know the exact error

    $row=mysql_num_rows($resource);
    if($row)
    {
    
    }
    else
    {
        mysql_error();
    }
    

    this will show you if there is problwm in mysql_num_rows

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序