ezeuba Posted June 17, 2013 Share Posted June 17, 2013 Good day all. I am trying to achieve entering multiple email addresses to a mysql database field all at once. I wrote the following script to manage this but it's not working. I am seperating the emails with comma, but it only enters this (') into the database. I am trying to use implode function but I don't seem to be getting it right. Any help will be appreciated. Here is the code: <?php if(isset($_POST['submit'])){ $email = $_POST['email']; if(empty($email)) { echo '<p><font color="red"><strong>NO EMAIL ADDRESSES ENTERED</strong></font></p>'; $badinput = '<p><font color="red"><strong>PLEASE INPUT MEMBERS' EMAIL ADDRESSES</strong></font></p>'; echo $badinput; } else{ mysql_connect("somehost","someadmin","somepassword");//database connection mysql_select_db("somedatabase"); //inserting data order $allemails="('".implode("'), ('",$email)."')"; $membersemail = "INSERT INTO sometable (email) VALUES ('$allemails')"; //declare in the order variable $result = mysql_query($membersemail); //$membersemail executes } if($result){ echo '<center><font color="red"><h1>SUCCESS!!!</h1></font></center>'; echo '<center><h3>DATABASE POPULATED WITH MEMBERS' EMAIL ADDRESSES</h3></center>'; } } ?> <form name= "someform" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <center><table border="0" cellspacing="10"> <tbody> <tr> <td align="right"><span class="style5">Members' E-mail Addresses:</span> </td> <td><label for="email"></label> <textarea name="email" id="email" cols="45" rows="10"></textarea> </td> </tr> </tbody></table> <input type="submit" name="submit" value="Submit"> <input type="reset" name="reset" value="Reset"></center> </form> What am I doing wrong? Thanks all. Link to comment https://forums.phpfreaks.com/topic/279281-help-with-database-multiple-record-entry-with-php/ Share on other sites More sharing options...
boompa Posted June 17, 2013 Share Posted June 17, 2013 See if this helps you with what you need to do: <?php $emails = '[email protected],[email protected],[email protected]'; $values = ''; foreach(explode(',', $emails) as $email) $values .= "('$email'),"; $query = "INSERT INTO emails VALUES " . rtrim($values, ','); echo "$query\n"; Link to comment https://forums.phpfreaks.com/topic/279281-help-with-database-multiple-record-entry-with-php/#findComment-1436480 Share on other sites More sharing options...
ezeuba Posted June 17, 2013 Author Share Posted June 17, 2013 See if this helps you with what you need to do: <?php $emails = '[email protected],[email protected],[email protected]'; $values = ''; foreach(explode(',', $emails) as $email) $values .= "('$email'),"; $query = "INSERT INTO emails VALUES " . rtrim($values, ','); echo "$query\n"; Thanks a lot. I am in your debt oh master of php... Link to comment https://forums.phpfreaks.com/topic/279281-help-with-database-multiple-record-entry-with-php/#findComment-1436483 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.