ecabrera Posted March 2, 2016 Share Posted March 2, 2016 OK so I want to be about to turn each line into a variable for example. I am retrieving emails sent to my email that look like this in the body content Name Address Town State Zip Car I want to be able to make each line into a variable instead of doing this. $query = mysqli_query($db,"SELECT * FROM email_leads WHERE email = '$company_email'"); while($rows = mysqli_fetch_assoc($query)){ $dbbody = nl2br($rows['body']); echo "<hr>$dbbody"; Any Ideas Quote Link to comment https://forums.phpfreaks.com/topic/300916-turn-each-new-line-into-a-variable/ Share on other sites More sharing options...
ecabrera Posted March 2, 2016 Author Share Posted March 2, 2016 solution : $dbbody = $rows['body']; $arr = explode("\n", $dbbody); Quote Link to comment https://forums.phpfreaks.com/topic/300916-turn-each-new-line-into-a-variable/#findComment-1531629 Share on other sites More sharing options...
Jacques1 Posted March 2, 2016 Share Posted March 2, 2016 Your query may be vulnerable to SQL injection attacks through the $company_email variable. Use a prepared statement instead. Also, this line-by-line format is very bad for automatic parsing. Who generates the e-mails? Is there a chance to send the data in a proper machine-readable format like JSON, XML etc.? This would make the parsing much easier and more robust. Quote Link to comment https://forums.phpfreaks.com/topic/300916-turn-each-new-line-into-a-variable/#findComment-1531630 Share on other sites More sharing options...
ginerjm Posted March 3, 2016 Share Posted March 3, 2016 You're storing the body element of an email in your table without trying to identify the individual parts of that email first? How do you know the 'body' is actually in the format you expect it to be in? Is this email a free-form entry from some user? Do you send back a confirmation email that lets the user know that what they think they sent you is actually what you interpreted it as? And - when you store this email, how do you identify it? You have all the content in one field - that means no keys, no dates, no tracking of any kind. Kind of defeats the purpose of maintaining a database, don't you think? If it were me and I absolutely had to obtain data this way, I would try to extract the data from the email and store it as a temporary record in a well-designed table with a reference key. I would then send the collected data items along with the reference key as a hidden field back to the user and ask for a reply that confirms their submission was correct. When that email comes back to a "special" address I would have another script designed to be triggered by emails coming in to it that would look for the reference key, locate the 'temporary' record and re-key it with the user's name (?) as the key and consider this entry as a valid one. Your current method of obtaining this data is flawed. GIGO - remember that? No self-respecting data processer would ever do what you are doing. Quote Link to comment https://forums.phpfreaks.com/topic/300916-turn-each-new-line-into-a-variable/#findComment-1531649 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.