renatovieita Posted January 16, 2015 Share Posted January 16, 2015 Hello guys, this is my first post so sorry if I made any mistake I need select record from one table and move to another table But I get this message saying "Warning: mysqli_query() expects at least 2 parameters, 1 given in" I had that on line 158, but now i get on line 156 I start to do PHP and mysql few weeks ago, only respond i get from teacher is search and search. <?php if (isset($_POST['username'])) { $searchq = $_POST['username']; mysqli_query("SELECT * FROM login WHERE username='$searchq'")or die ("could not search"); while($row = mysqli_fetch_array($con, $query)) { $username = $row['username']; $password = $row['password']; $age = $row['age']; $phonenumber = $row['phonenumber']; $nationality = $row['nationality']; mysqli_query("INSERT INTO admin SET username ='$username', password='$password', age='$age', phonenumber='$phonenumber', nationality='$nationality'" ) ; echo"Data successfully inserted"; } } ?> When i search i see this type of code "$data = mysqli_query" add variable before mysqli What should I do, to make it work. And send record from one table to another. Thank you Link to comment https://forums.phpfreaks.com/topic/293990-insert-into-one-table-to-another/ Share on other sites More sharing options...
Barand Posted January 16, 2015 Share Posted January 16, 2015 1. You need to assign the results of a SELECT query to a result object 2. mysqli_query requires the db connection object as the first argument 3. mysqli_fetch_xxxxx requires the result object as the argument. All you need is a single INSERT ... SELECT query. INSERT INTO admin (username, password, age, phonenumber, nationality) SELECT username, password, age, phonenumber, nationality FROM login WHERE username='$searchq' Link to comment https://forums.phpfreaks.com/topic/293990-insert-into-one-table-to-another/#findComment-1503154 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.