this is my php code for my profile.php. it is to display the users name after login.

<?php
session_start();

require "connect.php";
if($_SESSION['name'])
{
    $name =  $_SESSION['name'];
    $query =  mysql_query("SELECT name FROM register WHERE name ='$name'");
    $numrows = mysql_num_rows($query);

    if(1 == $numrows)
    {
        while ($rows = mysql_fetch_assoc($query))
        {
            echo "Welcome, ".$rows['name']."!"; 
        }
    }
}

?>

i want to display this:

while ($rows = mysql_fetch_assoc($query))
{
  echo "Welcome, ".$rows['name']."!"; 
}

inside html. ive tried but it isnt working. this is the code i did:

<?php while (@$rows = mysql_fetch_assoc(@$query))?><h3><?php echo "Welcome, ".@rows['name'] ?></h3>

but error : Parse error: syntax error, unexpected '[', expecting ',' or ';' in C:\xampp\htdocs\CashFlow\profile.php on line 37

<?php while (@$rows = mysql_fetch_assoc(@$query))?><h3><?php echo "Welcome, ".@rows['name'] ?></h3>

did you mean semi colon after @rows['name'] ? so it becomes @rows['name']; ??
well that didnt work. the same error still shows.

oh i figured out that @rows['name'] didnt have $ so now ive added that @$rows['name'] but no name appears. just 'welcome, '

If nothing is displaying, maybe the query failed, or there is a typo in the column name.

the name is the same.

even tried this:

<?php if(1 == $numrows) { ?><?php while (@$rows = mysql_fetch_assoc(@$query))?><h3><?php echo "Welcome, ".@$rows['name']; ?><?php }?>

same. just displays "Welcome,"

Did you connect and query in the same file? Add error handling, so you'll know when something's wrong.

i got the answer already pritaeas. i deleted php coding after session_start(); and in between html => <h3><?php echo "Welcome, ".@$_SESSION['name']."!" ?></h3> thanks for your input :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.