I could not insert data with same id as another table and my hobby column have comma in another table but and I have to insert in this table with same id and remove comma and after one hobby ,use new row to insert second hobby with same id please suggest

vrunda 0 Reputation points
2023-07-24T05:21:35.15+00:00
$hobby = implode(',',$_POST['hobby']);
		$sql = mysqli_query($conn,"INSERT INTO record(firstname,lastname,birthdate,age,phone_number,email,password,gender,hobby,picture,address)VALUES('".$_POST['firstname']."','".$_POST['lastname']."','".$_POST['birthdate']."','".$_POST['age']."','".$_POST['phone']."','".$_POST['email']."','".$_POST['password']."','".$_POST['gender']."','".$hobby."','".$image."','".$_POST['address']."')");
		
		
		if ($record = mysqli_query($conn,$sqlquery)) {
			while ($recordresult = mysqli_fetch_assoc($record)) {
				$hobbyname = explode(',',$recordresult['hobby']);
				foreach ($hobbyname as $hobby) {
					$insert = mysqli_query($conn,"INSERT INTO hobbyname(hname)VALUES('".$hobby."')");
					
				}
			}

first table name is : record 
second table name is : hobbyname which i have to insert with same id
Azure Database for MySQL
Azure Database for MySQL
An Azure managed MySQL database service for app development and deployment.
890 questions
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.