A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yeardisplaying the contents of a mysql query, only first field works - page 1
User InfoPosts
displaying the contents of a mysql query, only first field works#1
I am using a mysqli prepard query with php, the code is:

$retreiveQuery = (SELECT username, firstname, lastname FROM USERS WHERE username = ?(;

if ($getRecords = $con->prepare($retreiveQuery)) {
$getRecords->bind_param("s", $username);

$getRecords->execute();
$getRecords->bind_result($username, $firstname, $lastname);

echo "<h1>".$username."</h1>
<p><strong>First Name: </strong>".$firstname."
<p><strong>Surname: </strong>".$lastname."
} else {
print_r($con->error);


This is quite strange. username is the only field which is displayed. Why would the other columns not be being returned/bound?

If I do

SELECT username, firstname, lastname FROM USERS WHERE username = (test(;


Directly to the database, all fields are displayed, and all contain valid data.

posted date: 2009-04-08 13:01:00


Re: displaying the contents of a mysql query, only first field works#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-08 13:01:01


Re: displaying the contents of a mysql query, only first field works#3
What happens if you use a different variable name for output of username? Like this:SELECT username as user_name, firstname, lastname FROM USERS WHERE username = (test(;and then$getRecords->bind_result($user_name, $firstname, $lastname);I wonder if it(s getting confused by using the same name for both input and output?

posted date: 2009-04-08 13:05:00


Re: displaying the contents of a mysql query, only first field works#4
I haven(t run this, but I notice that you are using the same variable, $username for both the bound param and bound result variable.It may be that the result is not returning ANY of them, but $username has a value displayed because you are assigning it beforehand, not because it(s coming from the database.Try using different varaibles like $param_user and $result_user, and see what happens. My guess is that none of the result will be returned, which will point to a problem with the query or the result binding.

posted date: 2009-04-08 13:08:00


Re: displaying the contents of a mysql query, only first field works#5
You have to call$getRecords->fetch();after bind_result() to actually get the record.Username was being output because you had already set it, to use as an input parameter.

posted date: 2009-04-08 13:09:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.