Jump to content

Need help formating form data


gamak

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 <[email protected]>; Meg Griffin <[email protected]>; Stewie Griffin <[email protected]>

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

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("[email protected]", "[email protected]" , "[email protected]");

 

 

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.