0

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

2
Contributors
7
Replies
21
Views
4 Years
Discussion Span
Last Post by nadiam
0

<?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.

0

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

0

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,"

0

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

Edited by pritaeas

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.