Jump to content

[SOLVED] NOT working


RON_ron

Recommended Posts

Why isn't it working???  :confused:  :shrug:

 

<?php
$link = mysql_connect("localhost","inmy","inmypw1");
mysql_select_db("inmy_dyomails");

$query = 'SELECT * FROM dyomails';
$results = mysql_query($query);

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

var = mystring
$mystring = $urlText;
$findme   = '/?';
$pos = strpos($mystring, $findme);

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


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

echo "</dyomails>\n";

mysql_close($link);

?>

Link to comment
Share on other sites

Mchl... Oops! just ignore it. I was just trying things!

 

the code worked with out the extracting and the matching part. But I dont dont know how to EXTRACT the querystring (ID) and make it match with the Mysql database ID to get the relevat Email.

 

As mentioned This Code Works but I need to add the extracting and matching the db ID and returning the email part.

<?php
$link = mysql_connect("localhost","inmy","inmypw1");
mysql_select_db("indico_dyomails");

$query = 'SELECT * FROM dyomails';
$results = mysql_query($query);

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

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

echo "</dyomails>\n";

mysql_close($link);

?>

Link to comment
Share on other sites

Hi

 

There is no need to get everything from the database and check if it matches. Just bring back the (single?) matching row.

 

Something like this should do it:-

 

<?php
$link = mysql_connect("localhost","inmy","inmypw1");
mysql_select_db("inmy_dyomails");

$query = 'SELECT * FROM dyomails';
$results = mysql_query($query);

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

$mystring = $urlText;
$findme   = '/?';
$pos = strpos($mystring, $findme);

if ($pos !== false)
{
$pos += 2;
$SomeVar = mysql_real_escape_string(substr($mystring,$pos));
$query = "SELECT * FROM mail_list WHERE ID = '$SomeVar'";
$results = mysql_query($query);
if($line = mysql_fetch_assoc($results)) 
{
	echo "<item>" . $line["Email"] . "</item>\n";
}
}

echo "</dyomails>\n";

mysql_close($link);

?>

 

All the best

 

Keith

Link to comment
Share on other sites

I need a return value to tell flash it's successful. so i added the $sentOK. But it's not working.

 

CODE:

<?php
$link = mysql_connect("localhost","inmy","inmypw01");
mysql_select_db("inmy_dyomails");

$query = 'SELECT * FROM dyomails';
$results = mysql_query($query);

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

$mystring = $urlText;
$findme   = '/?';
$pos = strpos($mystring, $findme);

if ($pos !== false)
{
$pos += 2;
$SomeVar = mysql_real_escape_string(substr($mystring,$pos));
$query = "SELECT * FROM mail_list WHERE ID = '$SomeVar'";
$results = mysql_query($query);
if($line = mysql_fetch_assoc($results)) 
{
	echo "<item>" . $line["Email"] . "</item>\n";
}
}

$sentOk = ["Email"]; 

echo "</dyomails>\n";

mysql_close($link);

?>

Link to comment
Share on other sites

Hi

 

I have no idea how to pass a field back to flash. However I am pretty certain you cannot just assign a php field and have it passed back like that.

 

Also you probably want to set $sentOK to a blank at the start of the script and then put $sentOk = $line["Email"]; inside the if statement once you have found a matching record.

 

All the best

 

Keith

Link to comment
Share on other sites

What's the difference between A & B. Is B correct?

 

A:

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

 

 

B:

$urlText = $mystring;
$findme   = '/?';
$pos = strpos($mystring, $findme);

if ($pos !== false)
{
$pos += 2;
$SomeVar = mysql_real_escape_string(substr($mystring,$pos));
$query = "SELECT * FROM mail_list WHERE ID = '$SomeVar'";
$results = mysql_query($query);
if($line = mysql_fetch_assoc($results)) 
{
	echo "<item>" . $line["Email"] . "</item>\n";
}

Link to comment
Share on other sites

Hi

 

A is a very small part of B. Although A is looping round all possible matches while B is using IF and just getting the first match.

 

You can do it in php but it would be inefficient. For example if you had a million possible email addresses you would bring them all back and then loop through them to find a match (which would take ages and use a large amount of memory), whereas using sql you will just bring back the single one you are interested in.

 

All the best

 

Keith

Link to comment
Share on other sites

I'm feeling so much tired now by trying to fix this!!!!  >:(

 

 

Howcome A got $results & $line and B doesnt have them???

 

Also I'm wondering if there's something wrong in this piece of code which is blocking the entire Code.

 

urlText = The full URL from flash  |  The URL is: www.myweb.com/cotton.html/?ASD123456  & MySQL ID no is ASD123456

 

$urlText = $mystring;
$findme   = '/?';
$pos = strpos($mystring, $findme);

Link to comment
Share on other sites

Howcome A got $results & $line and B doesnt have them???

 

B does have them.

 

All B is doing is extracting the passed ID field (ie, locates "/?" in the URL you have passed, adds 2 to the position if found and then gets everything after that). It then looks for that particular ID within the ID field of the table.

 

I might have been confusing you using mail_list table rather than dyomails.

 

Bit of commented code to explain it a bit better:-

 

<?php
$link = mysql_connect("localhost","inmy","inmypw1");
mysql_select_db("inmy_dyomails");

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

// Assign the passed URL into $mystring (not sure where you are passing it from)
$mystring = $urlText;
$findme   = '/?';
// Locate the /? in the url
$pos = strpos($mystring, $findme);

// If the /? has been found (if it hasn't then $pos is set to false)
if ($pos !== false)
{
// Add 2 to the position
$pos += 2;
// Extract everything after /? from the passed URL. Escape it to remove any control characters
$SomeVar = mysql_real_escape_string(substr($mystring,$pos));
// Find any records from the table where the ID is the passed parameter
$query = "SELECT * FROM dyomails WHERE ID = '$SomeVar'";
$results = mysql_query($query);
// Get the first returned record, if one is found
if($line = mysql_fetch_assoc($results)) 
{
	// Output the first returned record
	echo "<item>" . $line["Email"] . "</item>\n";
}
}

echo "</dyomails>\n";
mysql_close($link);

?>

 

All the best

 

Keith

Link to comment
Share on other sites

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.