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
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'
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.