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 .....

<?php

$conn=mysql_connect("localhost","root","1");
    mysql_select_db("society",$conn);
    $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

Hi,

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
http://php.net/manual/en/function.mysql-query.php

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 http://php.net/manual/en/function.mysql-fetch-array.php
    echo $row['ID']; //it must be field name not number

By the way stop using mysql_connect instead use mysqli.

Warning
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:

mysqli_query()
PDO::query()

quote from http://php.net

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

<?php

    $conn=mysql_connect("localhost","root","1");
    mysql_select_db("society",$conn);
    $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

Hi,

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

and

<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 *

:-)

Hmm,

$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'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

<?php
$conn=mysql_connect("localhost","root","1")
or die(mysql_error());
    mysql_select_db("society",$conn)
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.

<?php
$conn=mysql_connect("localhost","root","1");
mysql_select_db("society",$conn);

$query = sprintf("
    select id, title, content, pic, date
    from news where id = %d
    ",
    mysql_real_escape_string($_GET['id'])
);
$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, networking, learning, and sharing knowledge.