can any one tell me how to use insert and select statement together with in a same table in mysql.my query is this
INSERT INTO `test` ( `id` , `UName` , `Password` )
SELECT '', 'Ahmed', 'Ahmed123'
FROM testbut it will return more than one rows inserted.but when i try this
INSERT INTO `test` ( `id` , `UName` , `Password` )
SELECT '', 'Ahmed', 'Ahmed123'
FROM testwhere id = 2;
it will return 0 row inserted .
my php code is this
$sql="INSERT into alumnireg(id,Fname,Mname,Lname,Email,Password)
select '','$fname','$mname','$lname','$email','$pass'
from alumnireg where Email = '$email' AND Password = '$pass'";
$result =mysql_query($sql);
confirm_query($result);
select '','$fname','$mname','$lname','$email','$pass'
from alumnireg where Email = '$email' AND Password = '$pass'";
$result =mysql_query($sql);
confirm_query($result);

Jaganathan BantheswaranRank #170 · 14.1K reputationPosted Jan 20, 2014, 8:15 PM EST
Do you want to insert data from another table regardless of condition [just copy all the data] or want to insert data only on some condition?
What you want exactly?
waseem shaikh17 reputationPosted Jan 20, 2014, 8:22 PM EST
first insert a data in a table then i just retrieve that data but same table
Biswa Pujarini MohapatraRank #465 · 5.4K reputationPosted Jan 20, 2014, 8:47 PM EST
I think you are looking to retrieve last inserted record using MySQL
check this thread
http://php.net/manual/en/function.mysql-insert-id.php
Jeetendra GundRank #97 · 22.1K reputationPosted Jan 20, 2014, 9:09 PM EST
$sql="INSERT into alumnireg(id,Fname,Mname,Lname,Email,Password)
select '','$fname','$mname','$lname','$email','$pass'
from alumnireg where Email = '$email' AND Password = '$pass'";
$result =mysql_query($sql);
confirm_query($result);
Remove that comma(,) and try.