Insert multiple email to mysql using single textarea

<?php
if(isset($_POST['submit'])) {
    //$email = nl2br($_POST['email']);
    $email = explode("\r\n", $_POST['email']);

    foreach($email as $emails) {
        $query = mysql_query("INSERT INTO emails (email) VALUES ('$emails')");
        if($query) {
            echo "Inserted into the database";
        } else {
            echo "Fail, please try again";
        }
    }
}
?>
<body>
    <form name="form1" method="POST">
        <textarea rows="5" name="email" cols="50" ></textarea>
        <br />
        <input type="submit" name="submit" value="submit">
    </form>
</body>
0
Subscribe to my newsletter

Read articles from Ogunuyo Ogheneruemu B directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ogunuyo Ogheneruemu B
Ogunuyo Ogheneruemu B

I'm Ogunuyo Ogheneruemu Brown, a senior software developer. I specialize in DApp apps, fintech solutions, nursing web apps, fitness platforms, and e-commerce systems. Throughout my career, I've delivered successful projects, showcasing strong technical skills and problem-solving abilities. I create secure and user-friendly fintech innovations. Outside work, I enjoy coding, swimming, and playing football. I'm an avid reader and fitness enthusiast. Music inspires me. I'm committed to continuous growth and creating impactful software solutions. Let's connect and collaborate to make a lasting impact in software development.