Jump to content

Err0r: mysql_fetch_row() expects parameter 1 to be resource, null given in C:\xampp\htdocs\PHP\lihat_detail.php on line 13


newbie_do

Recommended Posts

Hey guys I'm a student just studying PHP, I'm trying to make a newspage and I'm having this error in my code, can anyone help me with this code?

 

 

<html>
<body>
    <div align="center">
    <? include("atas.php");?>
    <table width="460" border="1" cellpadding="0" cellspacing="0"
    style="border-collapse: collapse" bordercolor="#111111" >
    <tr>
    <td width="460" bgcolor="#EAECCA" p align=center>
    <? include("./SDB.php");
        $db_name="";
        $hasil = mysql_query($db_name,"SELECT * FROM news
        order by id desc");
        while ($data = mysql_fetch_row($hasil))
        {
        $id=$data[0];
        $tanggal=$data[1];
        $judul=$data[2];
        $isi=$data[3];
        $foto=$data[4];
        $penulis=$data[5];
    ?>
<BR>
<? echo"<img src='./image/$foto' width=100 height=125
align=Left>"; ?>
<p align=justify><font color=#0C4BAB>
<b><? echo $judul; ?></b></font>
<BR>
Oleh:
<font color=blue><? echo($penulis);?></font>
<BR>
<? echo $tanggal; ?>
<BR>
<? echo $isi; ?><BR><BR><BR><BR>
<?
}
?>
</td>
</tr>
<tr>
<td width="460" bgcolor="#00428C"></td>
</tr>
</table><BR>
<? include("link.php");?>
</div>
</body>
</html>

lihat_detail.php

Edited by newbie_do
Link to comment
Share on other sites

since this is not ms sql, moving to the php help forum (your problem is the usage of the php functions, not the actual query, yet).

 

you should also be getting a warning/error message for the mysql_query() statement, it is the cause of the error you did post. when php functions are supplied with invalid parameters, they return null values now.

 

there's three problems with the mysql_query() statement in that code -

 

1) the order of the parameters for mysql_query() are - ($query , $link_identifier)

 

2) you are putting an empty string into a variable named $db_name and putting that into the mysql_query() statement. that makes no sense. the database name belongs in a select_db statement or in the actual sql query statement. it is not a parameter in any type of current query() statement.

 

3) the msyql (no i on the end) functions are depreciated. you should be using mysqli or pdo functions so that you don't have to rewrite your code at some point in the future.

Edited by mac_gyver
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.