Jump to content

Error in code


RON_ron

Recommended Posts

I have a MySQL database. and I'm stucked with the code below (AREA MARKED IN RED). I need to get an email to the matching string.

 

<?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 ID and get me the email.

Link to comment
https://forums.phpfreaks.com/topic/176525-error-in-code/
Share on other sites

yep! you are correct. But still how to extract the quesy string from the URL for matching.

 

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

 

I need advice on rewriting this part where it extracts the query string and match it with the MySQL ID field.

 

OR do you know how to request PHP to omit the text before the "/?" sign in the query string. Then PHP could match the remaining (?distributor11111111K) which is exactly what I want? How do I write that simple line?

Link to comment
https://forums.phpfreaks.com/topic/176525-error-in-code/#findComment-930562
Share on other sites

I see the lighthouse now!!  ;D  But do you think you could help me in fixing this code?

 

Where The Fixing needs to be done.

$sendURL = $_SERVER['QUERY_STRING']

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

if (in_array("['QUERY_STRING']",$line["ID"]))

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

}

 

 

It should pick only the relevent email (one email) from the database by matching the query string with the ID field in the MySQL.

 

 

 

FULL CODE:

<?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";

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

echo "</mail_list>\n";

mysql_close($link);

?>

Link to comment
https://forums.phpfreaks.com/topic/176525-error-in-code/#findComment-930572
Share on other sites

Sorry for delay.

 

 

// assuming the ONLY thing in the query string is the ID
$URL = $_SERVER['QUERY_STRING']; // changed, missing ';'
while($line = mysql_fetch_assoc($results)) {
if (in_array($URL,$line["ID"])) // changed from ['QUERY_STRING'] to $URL
   echo "<item>" . $line["Email"] . "</item>\n";
}

Link to comment
https://forums.phpfreaks.com/topic/176525-error-in-code/#findComment-932746
Share on other sites

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.