By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,963 Members | 1,249 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,963 IT Pros & Developers. It's quick & easy.

select into statement not working..help pls

P: n/a
hi,

what is wrong with my statement why it is not working:

$sel="select username,password into '$user','$pass'
from mytable where email = '$p' ";
mysql_query($sel) or die ('error: cannot perform query');
echo $user.' '.$pass;

my objective is to assign values to the local variables taking from
the table. what is the proper way to do it?

May 21 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"shotokan99" <so**********@yahoo.comwrote in message
news:11**********************@36g2000prm.googlegro ups.com...
hi,

what is wrong with my statement
The whole concept.
$sel="select username,password into '$user','$pass'
from mytable where email = '$p' ";
mysql_query($sel) or die ('error: cannot perform query');
echo $user.' '.$pass;

my objective is to assign values to the local variables taking from
the table.
It don't work like that, into has a very different meaning.
what is the proper way to do it?
Here's one way:

$sel="SELECT username, password FROM mytable WHERE email = '$p'";
$result = mysql_query($sel) or die ('error: cannot perform query');
list($user, $data) = mysql_fetch_array(result);
echo $user.' '.$pass;
--
Ra*********@gmail.com

"Good tea. Nice house." -- Worf
May 21 '07 #2

P: n/a
tnx..it did the trick

May 21 '07 #3

P: n/a
On 21 Mai, 09:05, shotokan99 <soft_devj...@yahoo.comwrote:
hi,

what is wrong with my statement why it is not working:

$sel="select username,password into '$user','$pass'
from mytable where email = '$p' ";
mysql_query($sel) or die ('error: cannot perform query');
echo $user.' '.$pass;

my objective is to assign values to the local variables taking from
the table. what is the proper way to do it?
Hi shotokan99,

you cant't assign result os an statement to local variables using
something like select ... into ...

You need to pass the result to mysql_fetch_array() or
mysql_fetch_row() to get the result of the executed query. Following
snippd shows the basic usage (without any errorhandling):
[snip]
$sel="select username, password from mytable where email = '$p' ";
$res = mysql_query($sel) or die ('error: cannot perform query');
$row = mysql_fetch_row($res);
echo $row[0].' '.$row[1];
[/snap]

purcaholic

May 21 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.