The programming page to view all the headlines and made the title link when pressed refer you to the details page, but unfortunately when the conversion page details are not shown to any details on the page

 <a style="color: red;" href="newspage.php?id=<?php echo $rows[0]?>"><?php echo $rows[1]?></a>

the details page code .....


    $strSQL = "SELECT * FROM news WHERE id=" . $_GET["id"];
    $row = mysql_fetch_array;
    echo $row[1];

So I want to know where the error and thank you very much in advance

Recommended Answers

All 15 Replies


Without looking at your code in detail I can see that you haven't executed the query.

e.g. $result = mysql_query($strSQL,$conn);

before your mysql_fetch_array line.

after line 5 you are not executing the mysql query.
Call the method mysql_query($strSQL );
See the php manual

Also there are few more erros .Check the code from line 5

    $strSQL = "SELECT * FROM yourtable WHERE ID=" . 1;
$result = mysql_query($strSQL);//missing this line
   while( $row = mysql_fetch_array($result))//proper way of using mysql_fetch_array
    echo $row['ID']; //it must be field name not number

By the way stop using mysql_connect instead use mysqli.

This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQL extension should be used. See also MySQL: choosing an API guide and related FAQ for more information. Alternatives to this function include:


quote from

Thank you ... but I could not really understand exactly what I do because I am new in the world of programming and there are many things not clear to me .. So is it possible to further clarification and Where do I put the execution exactly

I have used this code but there is still a problem


    $result = mysql_query($strSQL,$conn);
    $strSQL = "SELECT * FROM news WHERE id=" .$_GET["ID"];
    $result = mysql_query($strSQL);
    while( $row = mysql_fetch_array($result))
        echo $row['id'];

what is the problem can you expalin it???
Also with all mysql_connect(),mysql_selec_db() and mysql_query() use die() statement to know if there is any error in the connection or query.

$result = mysql_query($strSQL)
or die("ERROR".mysql_error());

Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in G:\AppServ\www\society\newspage.php on line 16


You also specificed $rows in your output instead of $row

$conn=mysql_connect("localhost","root","1"); mysql_select_db("society",$conn); $strSQL = "SELECT * FROM news WHERE id=" . $_GET["id"]; $result = mysql_query($strSQL,$conn); $row = mysql_fetch_array($result);


<a style="color: red;" href="newspage.php?id=<?php echo $row[0]?>"><?php echo $row[1]?></a>

I haven't done any proper testing. I also prefer mysql_fetch_assoc with $row['fieldname'] and good practice suggests not using select *



$strSQL = "SELECT * FROM news WHERE id=" . $_GET["id"];
$result = mysql_query($strSQL,$conn);
$row = mysql_fetch_array($result);

<a style="color: red;" href="newspage.php?id=<?php echo $row[0]?>"><?php echo $row[1]?></a>

I'm sorry for poor cognitive but I'm not good in English
The problem is that not introduce me details but appear blank page
But in the title shows the ID number in this path Localhost/society/newspage.php?id=49
But why not show the details ..

What are the database column names that you are displaying from your database? I'm guessing the first column is "id" what is the name of the second column?

id , title , content , pic , date

try smething like this.
The problem is because there is some database error.Either unable to connect or Wrong DB name.Add die() on each database methods to know the exact failure.Make sure database name is correct

or die(mysql_error());
or die(mysql_error());
     $strSQL = "SELECT * FROM news WHERE id=" . $_GET["id"];

$result1 = mysql_query($strSQL)
or die(mysql_error());

   while( $row = mysql_fetch_array($result1))
    echo $row['id']; 

Again, untested.


$query = sprintf("
    select id, title, content, pic, date
    from news where id = %d
$rs = mysql_query($query,$conn);
//echo mysql_error(); die;

$row = mysql_fetch_assoc($rs);
<a style="color: red;" href="newspage.php?id=<?php echo $row['id']?>"><?php echo $row['title']?></a>

IIM ...tha aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa U R my hero
thank you very much

paulkd.....your code it dosent do thing just clear page

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.