ronquiq
ronquiq

Reputation: 2707

Insert data into table at one time

This is my code

 echo    '<input type="submit" name="submit">';

I am getting the data from another table with this query

if($_POST['submit'])
 {
    $sql = mysql_query('SELECT q.username, q.firstanme,q.lastname FROM quizgroup q');
    foreach($sql as $s)
     {
        $username = $s->username;
        $firstname = $s->firstname;
        $lastname = $s->lastname;
        $sql = mysql_query('INSERT INTO user(username,firstname,lastname) VALUES('.$username.','.$first.','.$last.')');
     }
 }

Upvotes: 0

Views: 218

Answers (1)

Suresh kumar
Suresh kumar

Reputation: 2092

Try this

insert into user (SELECT username, firstanme, lastname FROM quizgroup)

This statement will copy the data from quizgroup to user table

Dont use "values" keyword when copy the data

Look at this

http://dev.mysql.com/doc/refman/5.0/en/insert-select.html

Upvotes: 2

Related Questions