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.

Link to comment
Share on other sites

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  :)
Link to comment
Share on other sites

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

 

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.