Page 1 of 1

I cannot retrieve data from the database.

Posted: Mon May 21, 2007 2:04 am
by m2babaey
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hi 
I cannot retrieve data from the database.
I use the following code and get the following error in the browser:
[b]Parse error: parse error in g:\programs(2)\easyphp1-8\www\ha\readarticle.php on line 11[/b]

code:

Code: Select all

<?php

mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("articles") or die(mysql_error());

$query="SELECT * FROM articles WHERE id='1'";
$result=mysql_query($query);
$row = mysql_fetch_array( $result );

echo $row=['text']."-". $row=['subject'] ;

mysql_close();
?>
line 11 is
echo $row=['text']."-". $row=['subject'] ;
thanks for your help


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon May 21, 2007 2:47 am
by bdlang
You're trying to assign the value of ['text'] to $row and then again with ['subject'].
What you mean to do is reference the $row array indices text and subject.

The line should be

Code: Select all

echo $row['text'] .'-'. $row['subject'];
Please read the PHP manual section on arrays.

Also, don't quote your INT values (the 1 should not be in quotes). This has nothing to do with the error, it's just bad practice.

This is strictly a PHP error, has nothing to do with the database. Have the thread moved.