Jump to content

INSERT INTO one table to another


renatovieita

Recommended Posts

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

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'

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.