nadiam Posted November 17, 2013 Share Posted November 17, 2013 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']."!"; } between some html. ive tried but it isnt working. this is the code i did: <?php if(1 == $numrows) { ?><?php while (@$rows = mysql_fetch_assoc(@$query))?><h3><?php echo "Welcome, ".@$rows['name']; ?><?php }?> i tried: <?php while (@$rows = mysql_fetch_assoc(@$query))?><h3><?php echo "Welcome, ".@$rows['name']; ?> but both doesnt work. as in only "Welcome, " is displayed in my page. any pointers is much appreciated! Link to comment https://forums.phpfreaks.com/topic/283992-echo-php-in-between-html-code/ Share on other sites More sharing options...
Ch0cu3r Posted November 17, 2013 Share Posted November 17, 2013 You already have the name in $_SESSION['name'] variable so why are you querying the database for their name again? You can just use this. echo "Welcome, ".$_SESSION['name']."!"; Also note you only use the while loop if your query returns more than one row. Link to comment https://forums.phpfreaks.com/topic/283992-echo-php-in-between-html-code/#findComment-1458660 Share on other sites More sharing options...
nadiam Posted November 17, 2013 Author Share Posted November 17, 2013 Thanks!! Link to comment https://forums.phpfreaks.com/topic/283992-echo-php-in-between-html-code/#findComment-1458661 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.