Page 1 of 1

[solved. thanks]parse error ($_session[], select)

Posted: Tue Jul 03, 2007 10:17 am
by m2babaey
Hi
this code is sending this error:
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in g:\programs(2)\easyphp1-8\www\ha\previous\new folder\another\htdocs\myarticles.php on line 5
code:

Code: Select all

<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("articles") or die(mysql_error());
$result = mysql_query("SELECT * FROM articles WHERE username=$_SESSION['username'] ORDER BY id") or die(mysql_error());
echo ?> <p align=center> your articles: </p>  <?
while($row = mysql_fetch_array( $result )) {
echo $row['subject']."<br>".$row['title']."<br>".$row['text']."<br><br>";
}
mysql_close();
?>

Posted: Tue Jul 03, 2007 10:22 am
by JayBird

Code: Select all

echo ?> <p align=center> your articles: </p>  <?
Why the extra echo? get rid of it

Posted: Tue Jul 03, 2007 10:22 am
by Gente
Here?

Code: Select all

echo ?> <p align=center> your articles: </p>  <?
while($row = mysql_fetch_array( $result ))
:wink:

Posted: Tue Jul 03, 2007 10:36 am
by m2babaey
I changed the code to:

Code: Select all

<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("articles") or die(mysql_error());
$result = mysql_query("SELECT * FROM articles WHERE username=$_SESSION['username'] ORDER BY id") or die(mysql_error());?> <p align=center> your articles </p>  <?
while($row = mysql_fetch_array( $result )) {
echo $row['subject'] "<br>".$row['title']."<br>".$row['text']."<br><br>";
}
mysql_close();
?>
but the same error yet

Posted: Tue Jul 03, 2007 10:43 am
by Jenk

Code: Select all

$result = mysql_query("SELECT * FROM articles WHERE username=$_SESSION['username'] ORDER BY id") or die(mysql_error());
to:

Code: Select all

$result = mysql_query("SELECT * FROM articles WHERE username={$_SESSION['username']} ORDER BY id") or die(mysql_error());
and use long tag: '<?php' not short tag: '<?'

May not 'fix' it, but process of elimination yada..

Posted: Tue Jul 03, 2007 11:19 am
by RobertGonzalez

Code: Select all

<?php
mysql_connect("localhost", "root", "") or die(mysql_error());
mysql_select_db("articles") or die(mysql_error());
$result = mysql_query("SELECT * FROM articles WHERE username = {$_SESSION['username']} ORDER BY id") or die(mysql_error());
?>
<p align="center">your articles:</p>
<?php
while ($row = mysql_fetch_array( $result )) {
    echo $row['subject'] . '<br />' . $row['title'] . '<br />' . $row['text'] . '<br /><br />';
}
mysql_close();
?>