IreneLing Posted October 9, 2011 Share Posted October 9, 2011 Hi all . In my scripts , there is a textarea that allow user to enter multiple phone number , message and date . If there are 3 phone numbers in textarea , how can I insert 3 of them into sql with the same data of message and date? Such as : phone number : 0102255888,0235544777,0896655444 message:hello all date:10/10/2011 and when it's insert into table , it will become: 1. 0102255888 | hello all | 10/10/2011 2. 0235544777 | hello all | 10/10/2011 3. 0896655444 | hello all | 10/10/2011 Here is the code I tried , but it will just save the last phone number . $cellphonenumber = explode(',', $_POST['cellphonenumber']); $message = $_POST['inputtext']; $date = $_POST['datetime']; foreach($cellphonenumber as $value) { $sql="INSERT INTO esp( Recipient , Message , Date) VALUES ('$value','$message','$date')"; } mysql_query($sql) or die ("Error: ".mysql_error()); echo "Database updated."; Any hints or advices ? Thanks for every reply . Quote Link to comment https://forums.phpfreaks.com/topic/248764-insert-multiple-data-into-mysql-with-explode/ Share on other sites More sharing options...
MasterACE14 Posted October 10, 2011 Share Posted October 10, 2011 You would have to move the mysql_query() into the foreach loop as well. That's why it's only executing the last query, because it's only executing the one query(the last in the loop). Quote Link to comment https://forums.phpfreaks.com/topic/248764-insert-multiple-data-into-mysql-with-explode/#findComment-1277614 Share on other sites More sharing options...
IreneLing Posted October 10, 2011 Author Share Posted October 10, 2011 You would have to move the mysql_query() into the foreach loop as well. That's why it's only executing the last query, because it's only executing the one query(the last in the loop). Thank you so much MasterACE14 , it works now , really thanks to your help . Thanks again and have a nice day . Quote Link to comment https://forums.phpfreaks.com/topic/248764-insert-multiple-data-into-mysql-with-explode/#findComment-1277660 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.