Jump to content

Newbie - match and return


RON_ron
 Share

Recommended Posts

I'm having a list of email addresses and I only want the PHP to select one of them at a time, depending on the information passed through the strings and into the form. When PHP receives the query string I would like PHP to extract it and match to an email address ("www.myweb.com/main.html?blaBLA" --> extract as "?blaBLA").

 

I'm using Flash (AS2) to do my form and I send data using LoadVars to PHP. Here's the pseudocode for what I'm trying to do. (I'm not sure if the syntext is correct). Please help me write this complete code.

 

where $list = "abc" then $email = "abcd@domain1.com"

where $list = "xyz" then $email = "pqurs@domain2.net"

where $list = "ghi" then $email = "uvwx@domain3.org"

(repeated 30 times for 30 email addresses!)

 

I hope that make sense! I'd preffer to have the code because I'm NOT a PHP gal at all!

Link to comment
Share on other sites

I record the URL in flash using js & flash externalinterface class. Then I send it to the PHP file (which is on the server).

 

PHP will receieve

www.myweb.com/online/pencils.html?distributor11111111K

 

Desired output:

james@abc.com

 

--------

The method here should be;

?distributor11111111K = james@abc.com

 

?distributor22222222K = franklin@apx.com

 

?distributor33333333K = Julie@xyz.com

 

Basically PHP should match the query string to an email address and return the email address. I hope that make more sense!

Link to comment
Share on other sites

OK... I have a MySQL database. and I'm stucked with the code below (AREA MARKED IN RED).

 

Using that I need to achieve the above mentioned. I've got ID / NAME / EMAIL / COMPANY in my Mysql database.

 

<?php

$link = mysql_connect("localhost","myname","mypw");

mysql_select_db("my_mails");

 

$query = 'SELECT * FROM mail_list';

$results = mysql_query($query);

 

echo "<?xml version=\"1.0\"?>\n";

echo "<mail_list>\n";

 

while($line = mysql_fetch_assoc($results)) {

if (in_array("?distributor11111111K",$ID))

echo "<item>" . $line["Email"] . "</item>\n";

}

 

echo "</mail_list>\n";

 

mysql_close($link);

 

?>

 

I want PHP to match the query string (?distributor11111111K) with an email.

Link to comment
Share on other sites

So you wish to output $line['email'] only if it contains distributor11111111K?

 

while($line = mysql_fetch_assoc($results)) {
if (strpos($line["Email"], "distributor11111111K"))
   echo "<item>" . $line["Email"] . "</item>\n";
}

Link to comment
Share on other sites

Hi

 

I would try something like this:-

 

<?php
$link = mysql_connect("localhost","myname","mypw");
mysql_select_db("my_mails");

$checkField = 'MaybeSomeDefaultTarget';

foreach($_GET AS $field => $value)
{
$checkField = mysql_real_escape_string($field);
}

$query = "SELECT * FROM mail_list WHERE ID = '$checkField'";
$results = mysql_query($query);

echo "<?xml version=\"1.0\"?>\n";
echo "<mail_list>\n";

if($line = mysql_fetch_assoc($results)) 
{
echo "<item>" . $line["Email"] . "</item>\n";
}

echo "</mail_list>\n";

mysql_close($link);

?>

 

All the best

 

Keith

Link to comment
Share on other sites

<?php
if ($current = each($_GET)) {
	mysql_connect("xxxxx","xxxxxx","xxxxxxxx");
	$q = mysql_query("SELECT * FROM table WHERE ID = '{$current['key']}'");
	echo "<?xml version=\"1.0\"?>\n";
	echo "<mail_list>\n";
	if ($row = mysql_fetch_assoc($q)) {
		echo "<item>{$row}</item>\n";
	}
	echo "</mail_list>";
}
?>

 

basically the same as Keith's but a lil shorter n stuff :)

 

Sorry I kinda left last night, I fell asleep :( I was tired.

Link to comment
Share on other sites

This thread is more than a year old.

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.

 Share

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