$show =$_GET; //if i put the id manually it works and the content get changes
print_r($_GET); // Working
$news_sql=mysql_query( "SELECT *FROM latestnews WHERE id = '$show' ");//i cant retrieve id here
while($rsnews = mysql_fetch_assoc($news_sql)){
?>

my code

<?php
}
?>

Recommended Answers

All 5 Replies

Check your form method in html page whether you have given method="get" or "post". if you gave get means, there will be no problem. If you use post and here you use $_GET, it definitely be a problem. And additionally, i suggest you to use post method, it is more reliable and have many advantages than Get method and this problem will get over. There is nothing in your code. Try it and solve.
If still any probs, please let me know..

You can still use the $_GET method to grab variables from your URL using form method="post", but you'd have to append the Id variable to the form action like this:

<form action="<?php 'process.php?id=$id' ?>" method="post">

(that's if you're actually using a form, you haven't stated whether you are).

Can you be a bit more specific with what you're trying to do?

Oh... But this id passing through code cannot works sometimes in Mozilla, IE and Opera. This will not works perfectly some times. So, directly passing through code is not good practice. I am sorry if my suggestion hurts..

Your sql query has a syntax error in it. There should be a space after *:

$news_sql=mysql_query( "SELECT * FROM latestnews WHERE id = '$show' ");

The query will still work even if there isn't a space between the asterisk and the 'FROM'
The query looks fine. The issue is most likely with the variable not being set.
Try this and post the result:

<?php
    $show = $_GET['id'];

    if (isset($show))
    {
        $news_sql = mysql_query("SELECT *FROM latestnews WHERE id='$show'") or die("MySQL syntax error: ". mysql_error());
    }
    else { die ('$show isn't set! the $_get didn't work...'); }
?>

Note:- The $_GET must mean that the URL has a variable called 'id' (www.site.com/script.php?id=2)
And say I used $_GET then the url should be something like (www.site.com/script.php?foo=bar)

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.