Jump to content

Newbie - match and return


RON_ron

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 = "[email protected]"

where $list = "xyz" then $email = "[email protected]"

where $list = "ghi" then $email = "[email protected]"

(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
https://forums.phpfreaks.com/topic/176516-newbie-match-and-return/
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:

[email protected]

 

--------

The method here should be;

?distributor11111111K = [email protected]

 

?distributor22222222K = [email protected]

 

?distributor33333333K = [email protected]

 

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

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.

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

<?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.

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.