Jump to content

Recommended Posts

Okay, So i'm a n00b at PHP, and I was hoping someone  help me out.

 

I have a form with one large text box which the user basically copies data into.  The data copied into the text box looks like this:

 

-------example of copied data---------------------------------------------

Peter Griffin <peterG@gmail.com>; Meg Griffin <meg@gmail.com>; Stewie Griffin <stewie@gmail.com>

--------------------------------------------------------------------------

The form data is then sent to proccessbigtextboxpage.php ( I know how to do this)

 

What I need to do is some how take the First Name and Last name and Email address and break it up and store it into a database.

 

So I can get the data to  look something like:

 

$first_name = array("peter", "meg", "stewie");

$last_name = array ("griffin", "griffin", "griffin");

$email_address = array("peter@gmail.com", "stewie@gmail.com" , "meg@gmail.com");

 

 

I know how to store all of the data into a database, but I don't know how to break it all up to store it into a database.  I think it has something to do with preg_match and PRCE or something, but I'm really lost.

Link to comment
https://forums.phpfreaks.com/topic/145700-need-help-formating-form-data/
Share on other sites

Something like this may help. untested but should be close to what you want

 

 

<?php

foreach (split(";",$_POST['data']) as $person){

$details = split("<",$person);
$name = $details[0];
$email = preg_replace('>','',$details[1]);
$query = ""; //your job

}

?>

 

 

I tried you code, but the output doesn't seem to be working for the emails. Here is what outputs when I use your code.

<?php
$email_list = $_POST['email'];

foreach (split(";",$_POST['email']) as $person){

$details = split("<",$person);
$name = $details[0];
$email = preg_replace('>','',$details[1]);
echo " Name: $name \n "; 
echo " Email: $email \n"; 

//$query = ""; //your job

}

?>

 

-------------------Output------------

Name: Meg Griffin Email: Name: Peter Griffin Email:

--------------------------------------

 

The email is blank.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.