Jump to content

Doesn´t return value of variable??


Fenhopi

Recommended Posts

I have this code:

<body>
<?php
// load config file
include("dbconfig.php");

$result = mysql_query("SELECT * FROM news WHERE newsid='$newsid' ",$connect); 
while($myrow = mysql_fetch_assoc($result)) 
{
echo "Title: <h1>";
echo $myrow['title'];
echo "</h1><br><br> Teaser: ";
echo $myrow['text1'];
echo "<br><hr>";
echo "On: <i>";
echo $myrow['dtime'];
echo "</i><hr align=left width=160><br><br>";


}

?>

This is the code that is executed when I hit read more on my news feed. But when it select for example newsid=5 it returns with a blank page.

Please help.


</body>
</html>

Link to comment
Share on other sites

It seems like you are used to working with PHP and register_globals being turned on. This has been off by default in PHP 4.x versions + due to the security vulnerabilities it creates.

 

Try something like this and see if it works:

<?php
// load config file
include("dbconfig.php");

$newsid = isset($_GET['newsid'])?(int) $_GET['newsid']:0;

$result = mysql_query("SELECT * FROM news WHERE newsid='$newsid' ",$connect); 
while($myrow = mysql_fetch_assoc($result)) 

 

Basically it checks if newsid was passed in. If it was it converts it to an INT to avoid a possible sql injection. If not it passes 0, you can do error checks etc here if you would like, but should give you a basic structure.

 

The ? : are the ternary operator which acts as a shortened else / if incase you were wondering.

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.