Printing PHP value on page

Posted on 2013-01-25
Last Modified: 2013-01-25
Hi all,

This is simple question but I think using the PHPfox it might be causing some issues.

I am using this SQL statement to get a value (it will be either no value or 1 value) from the DB:

	$query = mysql_query("SELECT question FROM cometchat_question WHERE userid = '$username' ");

Open in new window

I want to print this on a form on the page. How do I do this?


Question by:TLN_CANADA
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38821011
$query in that statement will only be a resource identifier, not the data you are looking for.  You still need to use mysql_fetch_array() or one of the other methods to get the actual data, even if it is only one item.

Author Comment

ID: 38821026
Here is what I have but it's giving an error:

$query = mysql_query("SELECT question FROM cometchat_question WHERE userid = '$username' ");
	$row = mysql_fetch_array($query)
	echo $row ;

Open in new window

Parse error: syntax error, unexpected T_ECHO in /home/clear555/public_html/dyadmenu.php on line 48
LVL 83

Expert Comment

by:Dave Baldwin
ID: 38821050
You need a semi-colon ';' at the end of the second line.  Like...
$row = mysql_fetch_array($query);

Open in new window


Author Comment

ID: 38821075
Thanks, it's strange when I run the sql statement in the db it returns the result correct but when I print the array like this on the page it comes up blank. The username prints correct so it is connecting to the DB.

It would be a varchar format the question field that I am trying to fetch.

In this case the correct result from the db would be "Hello World"

$username = Phpfox::getUserBy('user_id'); 
	echo $username ;
	// Check for question
	$query = mysql_query("SELECT question FROM cometchat_question WHERE userid = '$username' ");
	$row = mysql_fetch_array($query) ;
	echo $row ;

Open in new window

LVL 83

Accepted Solution

Dave Baldwin earned 500 total points
ID: 38821173
$row is an array in this case.  Your last line needs to be:
echo $row['question'];

Open in new window


Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Wordpress Pagination 1 46
Codeigniter Query Help Returning JSON 4 50
$_SERVER Variable question 31 56
How do I speed up this PDO query 4 15
Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question