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