waseem shaikh

waseem shaikh

  • NA
  • 22
  • 6.4k

how to use insert and select statement together

Jan 21 2014 1:03 AM
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 test
 
but it will return more than one rows inserted.but when i try this 
 
INSERT INTO `test` ( `id` , `UName` , `Password` )
SELECT '', 'Ahmed', 'Ahmed123'
FROM test
where  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);

 

Answers (4)