Jump to content

Quick question regarding undefined variable.


fonster_mox

Recommended Posts

Hi, I'm very new to php so I don't really know what I am doing.

 

I am recieving the message

Notice: Undefined variable: row in /mysite.com/article.php on line 62

 

I know this is because I haven't defined $row but I don't know what it's supposed to be defined as, or where :( as I said, very new to php!

 

the page is supposed to get the id from the url, eg article.php?=10 should post only the row of the table with the id 10.

 

  <?

$id=$row["id"];
$db=mysql_connect("localhost","*****","*****") or die ('cant connect');
mysql_select_db("*****",$db) or die ("cant change");
$news=mysql_query("select * from news WHERE id='$id' ORDER BY id DESC LIMIT 1") or die ("cant get table");
while($rows=mysql_fetch_array($news)){ 

$body=$rows["body"];
$title=$rows["title"];
$date=$rows["date"];
$author=$rows["author"];
$email=$rows["email"];
$smallcontent=$rows["smallcontent"];



echo "<div class=\"newsitem\">
                                                        <div class=\"newstop\"></div>
                                                            <div class=\"newsmiddle\">
                                                            <div class=\"innernews\">
                            <span class=\"newshead\">$title</span><br />
                            <span class=\"byline\">By <a href=\"mailto:$email\">$author</a> on $date</span><br /><br />
                            $body
						<br /><br />
						                                                         </div>
                                                            </div>
                                                        <div class=\"newsbottom\"></div>
                </div>";


}
?>            

 

would be really grateful with  an explanation of what I've done wrong or just the correct way to do it,

 

thanks,

fonmo.

I've tried using this page but I still can't figure it out. I appreciate that you're trying to get me to help myself but I don't even understand most of the code I have so far (a friend helped me through it, who's on holiday now). To fix my own problem using the link you've provided would mean going back a few dozen steps to learn some basics first, which I don't really have time for. But I'm quite sure if someone just showed me what I'm missing (I'm sure it's very easy for someone with experience, it's a very basic news post system linking to a full size article, the site you can find on thousands of sites already), I'm sure I would learn a lot from it. Thanks, anyway  :)

I take that back (sorry to double post, but modify has gone, I assume it's on a timer).

 

I did figure it out, thank you! It was thanks to being swerved back to that GET code. I had googled previously and thought GET was what I needed, but couldn't get it right. In the end, your insistence and a bit of trial and error proved me wrong. All I needed was

 

$id=$_GET['id'];

above

$news=mysql_query("select * from news WHERE id='$id' ORDER BY id DESC LIMIT 1") or die ("cant get table");

 

Thanks again, consider this solved and closable :)

 

Archived

This topic is now archived and is closed to further replies.

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