PHP mail, generate on click, build from record in table

My code is pasted in the code box.
I need to add email functionality as follows:

First to familiarize yourself, click here, then select a manufacturer from the dropdown and click Search.
In the resulting table, you can see that the last field contains a link. Now, some items have a SKU#, and for those that do, I need nothing done, the user will click through to the proper place. However for those items which do not have SKUs, I need an email generated. The email will require no input from the user, other than clicking on the link. The email needs to contain the following data: Manufacturer and catalog# (2 fields in the database).
Then, I need the user (if clicking on an item's link with no SKU) to be redirected to a small form page where text is displayed like: "Thank for your interest in the $manufacturer item $catalog. They can enter their email,name, and phone number, and a small message if needed. Then when they click submit, I'll receive a second email message containing the input from the user.

I can build the emails, but I need to know how to generate the email from the OnClick() once the users clicks the link with no SKU. I dont know the syntax or logic to use in PHP.

Thanks so very much!

-Tortuga
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 
<html>
<head>
<title>Product Catalog</title>
</head>
<body background="" bgcolor="silver">
 
<?php
 
require 'pre_var.php';
 
if (!($connection = mysql_connect($hostname, $username, $password)))
{
    die("Could not connect");
}
if (!(mysql_select_db($databaseName, $connection)))
{
    showerror();
    die("Could not Select");
}
 
 
if (empty($_POST))
{
   $sql = "SELECT DISTINCT MANUFACTURER FROM main ORDER BY MANUFACTURER";
   $res = mysql_query($sql);
   if (!$res) die( mysql_error() );
   
	 echo "<table><tr><td>";
	 
	 echo "<form method=\"post\">\n";
   echo "Search by Manufacturer:<br />\n";
   echo "<select name=\"m\">\n";
   echo "<option>-Select Manufacturer-</option>";
       while ($row = mysql_fetch_assoc($res))
   {
       $m = $row["MANUFACTURER"];
       echo "<option>$m</option>\n";
   }
   echo "</select>\n";
   echo "<input value=\"Search\" type=\"submit\">\n";
   echo "</form>\n";
	 
	 echo "</td></tr>";
   echo "</tr><td>";
	 
	 echo "<form method=\"post\">\n";
   echo "Search by Part# or Description:<br />\n";
   echo "<input name=\"descript\" >\n";
   echo "<input name=\"searchExact\" value=\"Search exact\" type=\"submit\">\n";
   echo "<input name=\"searchLike\"  value=\"Search similar...\" type=\"submit\">\n";
   echo "<input type='radio' NAME='whichType' value='DESCRIPTION'> by Description";
   echo "<input type='radio' NAME='whichType' value='CATALOG' CHECKED> by Part#";
   echo "</form>\n";
	 
	 echo "</td></tr></table>";
} 
else
{
   $descript    = mysql_real_escape_string($_POST["descript"]);
   $searchExact = mysql_real_escape_string($_POST["searchExact"]);
   $searchLike  = mysql_real_escape_string($_POST["searchLike"]);
   $whichType   = mysql_real_escape_string($_POST["whichType"]);
   
   
   if($searchExact==='Search exact')
   {
      $query = "SELECT * FROM main WHERE $whichType = \"$descript\" ORDER BY MANUFACTURER, CATALOG";
   }
   elseif($searchLike==='Search similar...')
   {
      $query = "SELECT * FROM main WHERE $whichType LIKE \"%$descript%\" ORDER BY MANUFACTURER, CATALOG";
   }
   elseif(isset($_POST["m"]))
   {
      $m = mysql_real_escape_string($_POST["m"]);
      $query = "SELECT * FROM main WHERE MANUFACTURER = \"$m\" ORDER BY CATALOG";
   }
   if (!($result = mysql_query ($query, $connection)))
   {
       showerror();
       die("Query Error");
   }
   
   displayItems($result);
}
 
 
function displayItems($result)
{
 		echo "<a href='javascript:history.back()'><< Back</a>";
    echo "<h2>Your Search Results:</h2>" ;
    echo "\n<table border=1 align=left>\n<tr>\n" .
       "\n\t<td><b>Catalog/Part#</b></td>" .
       "\n\t<td><b>Item Description</b></td>" .
       "\n\t<td><b>Manufacturer</b></td>" .
       "\n\t<td><b>UPC Code</b></td>" .
       "\n\t<td><b>Order Info</b></td>" .
       "\n</tr>";
    while ($row = mysql_fetch_assoc($result))
    {
   
        extract($row);
        echo "\n<tr>";
        echo "\n\t<td align=left> {$CATALOG} </td>";
        echo "\n\t<td align=left> {$DESCRIPTION} </td>";
        echo "\n\t<td align=left> {$MANUFACTURER} </td>";
        echo "\n\t<td align=left> {$UPC_CODE} </td>";
        echo "\n\t<td align=left> <a href='http://www.url.com/product.php?id={$SKU}'> Click Here </td>";
       
			 	echo "\n</tr>\n";
    }
    echo "\n</table>";
		echo "\n<table align=left>";
		echo "\n</tr>\n";
		echo "\n\t<td>This should be the bottom of the page</td>";
		echo "\n</tr>";
		echo "\n</table>";            
}
?>
 
</body>
</html>

Open in new window

TortugaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NerdsOfTechTechnology ScientistCommented:
Can you explain what happens when they click on a product that HAS a SKU opposed to NOIT HAVING a SKU.

Thanks
0
TortugaAuthor Commented:
Sure, if the product has a SKU, then the URL that they click through to is constructed like : http://www.url.com/product.php?SKU , or similar, which is actually a valid URL to the product's page on another site.

If no SKU, then when clicked on, the notification email is sent to me, and then user is directed to the simple form to enter contact info.

clear as mud? or is that somewhat definitive?
0
NerdsOfTechTechnology ScientistCommented:
You could check for SKU <> "" ? if so output regular link
: If not, then output link to nosku.php
(which would do the email process and redirect your user to a form)

Solved.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 
<html>
<head>
<title>Product Catalog</title>
</head>
<body background="" bgcolor="silver">
 
<?php
 
require 'pre_var.php';
 
if (!($connection = mysql_connect($hostname, $username, $password)))
{
    die("Could not connect");
}
if (!(mysql_select_db($databaseName, $connection)))
{
    showerror();
    die("Could not Select");
}
 
 
if (empty($_POST))
{
   $sql = "SELECT DISTINCT MANUFACTURER FROM main ORDER BY MANUFACTURER";
   $res = mysql_query($sql);
   if (!$res) die( mysql_error() );
   
         echo "<table><tr><td>";
         
         echo "<form method=\"post\">\n";
   echo "Search by Manufacturer:<br />\n";
   echo "<select name=\"m\">\n";
   echo "<option>-Select Manufacturer-</option>";
       while ($row = mysql_fetch_assoc($res))
   {
       $m = $row["MANUFACTURER"];
       echo "<option>$m</option>\n";
   }
   echo "</select>\n";
   echo "<input value=\"Search\" type=\"submit\">\n";
   echo "</form>\n";
         
         echo "</td></tr>";
   echo "</tr><td>";
         
         echo "<form method=\"post\">\n";
   echo "Search by Part# or Description:<br />\n";
   echo "<input name=\"descript\" >\n";
   echo "<input name=\"searchExact\" value=\"Search exact\" type=\"submit\">\n";
   echo "<input name=\"searchLike\"  value=\"Search similar...\" type=\"submit\">\n";
   echo "<input type='radio' NAME='whichType' value='DESCRIPTION'> by Description";
   echo "<input type='radio' NAME='whichType' value='CATALOG' CHECKED> by Part#";
   echo "</form>\n";
         
         echo "</td></tr></table>";
} 
else
{
   $descript    = mysql_real_escape_string($_POST["descript"]);
   $searchExact = mysql_real_escape_string($_POST["searchExact"]);
   $searchLike  = mysql_real_escape_string($_POST["searchLike"]);
   $whichType   = mysql_real_escape_string($_POST["whichType"]);
   
   
   if($searchExact==='Search exact')
   {
      $query = "SELECT * FROM main WHERE $whichType = \"$descript\" ORDER BY MANUFACTURER, CATALOG";
   }
   elseif($searchLike==='Search similar...')
   {
      $query = "SELECT * FROM main WHERE $whichType LIKE \"%$descript%\" ORDER BY MANUFACTURER, CATALOG";
   }
   elseif(isset($_POST["m"]))
   {
      $m = mysql_real_escape_string($_POST["m"]);
      $query = "SELECT * FROM main WHERE MANUFACTURER = \"$m\" ORDER BY CATALOG";
   }
   if (!($result = mysql_query ($query, $connection)))
   {
       showerror();
       die("Query Error");
   }
   
   displayItems($result);
}
 
 
function displayItems($result)
{
                echo "<a href='javascript:history.back()'><< Back</a>";
    echo "<h2>Your Search Results:</h2>" ;
    echo "\n<table border=1 align=left>\n<tr>\n" .
       "\n\t<td><b>Catalog/Part#</b></td>" .
       "\n\t<td><b>Item Description</b></td>" .
       "\n\t<td><b>Manufacturer</b></td>" .
       "\n\t<td><b>UPC Code</b></td>" .
       "\n\t<td><b>Order Info</b></td>" .
       "\n</tr>";
    while ($row = mysql_fetch_assoc($result))
    {
   
        extract($row);
        echo "\n<tr>";
        echo "\n\t<td align=left> {$CATALOG} </td>";
        echo "\n\t<td align=left> {$DESCRIPTION} </td>";
        echo "\n\t<td align=left> {$MANUFACTURER} </td>";
        echo "\n\t<td align=left> {$UPC_CODE} </td>";
        echo "\n\t<td align=left> " . ($SKU <> "" ? "<a href='http://www.url.com/product.php?id={$SKU}'> Click Here </a></td>" : "<a href='http://www.url.com/nosku.php'>Click Here</a></td>";
       
                                echo "\n</tr>\n";
    }
    echo "\n</table>";
                echo "\n<table align=left>";
                echo "\n</tr>\n";
                echo "\n\t<td>This should be the bottom of the page</td>";
                echo "\n</tr>";
                echo "\n</table>";            
}
?>
 
</body>
</html>

Open in new window

0
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

NerdsOfTechTechnology ScientistCommented:
Fixed, USE THIS VERSION INSTEAD. the previous had 1 syntax error.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 
<html>
<head>
<title>Product Catalog</title>
</head>
<body background="" bgcolor="silver">
 
<?php
 
require 'pre_var.php';
 
if (!($connection = mysql_connect($hostname, $username, $password)))
{
    die("Could not connect");
}
if (!(mysql_select_db($databaseName, $connection)))
{
    showerror();
    die("Could not Select");
}
 
 
if (empty($_POST))
{
   $sql = "SELECT DISTINCT MANUFACTURER FROM main ORDER BY MANUFACTURER";
   $res = mysql_query($sql);
   if (!$res) die( mysql_error() );
   
         echo "<table><tr><td>";
         
         echo "<form method=\"post\">\n";
   echo "Search by Manufacturer:<br />\n";
   echo "<select name=\"m\">\n";
   echo "<option>-Select Manufacturer-</option>";
       while ($row = mysql_fetch_assoc($res))
   {
       $m = $row["MANUFACTURER"];
       echo "<option>$m</option>\n";
   }
   echo "</select>\n";
   echo "<input value=\"Search\" type=\"submit\">\n";
   echo "</form>\n";
         
         echo "</td></tr>";
   echo "</tr><td>";
         
         echo "<form method=\"post\">\n";
   echo "Search by Part# or Description:<br />\n";
   echo "<input name=\"descript\" >\n";
   echo "<input name=\"searchExact\" value=\"Search exact\" type=\"submit\">\n";
   echo "<input name=\"searchLike\"  value=\"Search similar...\" type=\"submit\">\n";
   echo "<input type='radio' NAME='whichType' value='DESCRIPTION'> by Description";
   echo "<input type='radio' NAME='whichType' value='CATALOG' CHECKED> by Part#";
   echo "</form>\n";
         
         echo "</td></tr></table>";
} 
else
{
   $descript    = mysql_real_escape_string($_POST["descript"]);
   $searchExact = mysql_real_escape_string($_POST["searchExact"]);
   $searchLike  = mysql_real_escape_string($_POST["searchLike"]);
   $whichType   = mysql_real_escape_string($_POST["whichType"]);
   
   
   if($searchExact==='Search exact')
   {
      $query = "SELECT * FROM main WHERE $whichType = \"$descript\" ORDER BY MANUFACTURER, CATALOG";
   }
   elseif($searchLike==='Search similar...')
   {
      $query = "SELECT * FROM main WHERE $whichType LIKE \"%$descript%\" ORDER BY MANUFACTURER, CATALOG";
   }
   elseif(isset($_POST["m"]))
   {
      $m = mysql_real_escape_string($_POST["m"]);
      $query = "SELECT * FROM main WHERE MANUFACTURER = \"$m\" ORDER BY CATALOG";
   }
   if (!($result = mysql_query ($query, $connection)))
   {
       showerror();
       die("Query Error");
   }
   
   displayItems($result);
}
 
 
function displayItems($result)
{
                echo "<a href='javascript:history.back()'><< Back</a>";
    echo "<h2>Your Search Results:</h2>" ;
    echo "\n<table border=1 align=left>\n<tr>\n" .
       "\n\t<td><b>Catalog/Part#</b></td>" .
       "\n\t<td><b>Item Description</b></td>" .
       "\n\t<td><b>Manufacturer</b></td>" .
       "\n\t<td><b>UPC Code</b></td>" .
       "\n\t<td><b>Order Info</b></td>" .
       "\n</tr>";
    while ($row = mysql_fetch_assoc($result))
    {
   
        extract($row);
        echo "\n<tr>";
        echo "\n\t<td align=left> {$CATALOG} </td>";
        echo "\n\t<td align=left> {$DESCRIPTION} </td>";
        echo "\n\t<td align=left> {$MANUFACTURER} </td>";
        echo "\n\t<td align=left> {$UPC_CODE} </td>";
        echo "\n\t<td align=left> " . ($SKU <> "" ? "<a href='http://www.url.com/product.php?id={$SKU}'> Click Here </a></td>" : "<a href='http://www.url.com/nosku.php'>Click Here</a></td>");
       
                                echo "\n</tr>\n";
    }
    echo "\n</table>";
                echo "\n<table align=left>";
                echo "\n</tr>\n";
                echo "\n\t<td>This should be the bottom of the page</td>";
                echo "\n</tr>";
                echo "\n</table>";            
}
?>
 
</body>
</html>

Open in new window

0
NerdsOfTechTechnology ScientistCommented:
Actually... better yet nevermind.

USE YOUR ORIGINAL CODE

howerver, in http://www.url.com/product.php?SKU check for the blank SKU first!

If blank, send user to a page that will email you and where the user can fill out the form you want.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 
<html>
<head>
<title>Product Catalog</title>
</head>
<body background="" bgcolor="silver">
 
<?php
 
require 'pre_var.php';
 
if (!($connection = mysql_connect($hostname, $username, $password)))
{
    die("Could not connect");
}
if (!(mysql_select_db($databaseName, $connection)))
{
    showerror();
    die("Could not Select");
}
 
 
if (empty($_POST))
{
   $sql = "SELECT DISTINCT MANUFACTURER FROM main ORDER BY MANUFACTURER";
   $res = mysql_query($sql);
   if (!$res) die( mysql_error() );
   
	 echo "<table><tr><td>";
	 
	 echo "<form method=\"post\">\n";
   echo "Search by Manufacturer:<br />\n";
   echo "<select name=\"m\">\n";
   echo "<option>-Select Manufacturer-</option>";
       while ($row = mysql_fetch_assoc($res))
   {
       $m = $row["MANUFACTURER"];
       echo "<option>$m</option>\n";
   }
   echo "</select>\n";
   echo "<input value=\"Search\" type=\"submit\">\n";
   echo "</form>\n";
	 
	 echo "</td></tr>";
   echo "</tr><td>";
	 
	 echo "<form method=\"post\">\n";
   echo "Search by Part# or Description:<br />\n";
   echo "<input name=\"descript\" >\n";
   echo "<input name=\"searchExact\" value=\"Search exact\" type=\"submit\">\n";
   echo "<input name=\"searchLike\"  value=\"Search similar...\" type=\"submit\">\n";
   echo "<input type='radio' NAME='whichType' value='DESCRIPTION'> by Description";
   echo "<input type='radio' NAME='whichType' value='CATALOG' CHECKED> by Part#";
   echo "</form>\n";
	 
	 echo "</td></tr></table>";
} 
else
{
   $descript    = mysql_real_escape_string($_POST["descript"]);
   $searchExact = mysql_real_escape_string($_POST["searchExact"]);
   $searchLike  = mysql_real_escape_string($_POST["searchLike"]);
   $whichType   = mysql_real_escape_string($_POST["whichType"]);
   
   
   if($searchExact==='Search exact')
   {
      $query = "SELECT * FROM main WHERE $whichType = \"$descript\" ORDER BY MANUFACTURER, CATALOG";
   }
   elseif($searchLike==='Search similar...')
   {
      $query = "SELECT * FROM main WHERE $whichType LIKE \"%$descript%\" ORDER BY MANUFACTURER, CATALOG";
   }
   elseif(isset($_POST["m"]))
   {
      $m = mysql_real_escape_string($_POST["m"]);
      $query = "SELECT * FROM main WHERE MANUFACTURER = \"$m\" ORDER BY CATALOG";
   }
   if (!($result = mysql_query ($query, $connection)))
   {
       showerror();
       die("Query Error");
   }
   
   displayItems($result);
}
 
 
function displayItems($result)
{
 		echo "<a href='javascript:history.back()'><< Back</a>";
    echo "<h2>Your Search Results:</h2>" ;
    echo "\n<table border=1 align=left>\n<tr>\n" .
       "\n\t<td><b>Catalog/Part#</b></td>" .
       "\n\t<td><b>Item Description</b></td>" .
       "\n\t<td><b>Manufacturer</b></td>" .
       "\n\t<td><b>UPC Code</b></td>" .
       "\n\t<td><b>Order Info</b></td>" .
       "\n</tr>";
    while ($row = mysql_fetch_assoc($result))
    {
   
        extract($row);
        echo "\n<tr>";
        echo "\n\t<td align=left> {$CATALOG} </td>";
        echo "\n\t<td align=left> {$DESCRIPTION} </td>";
        echo "\n\t<td align=left> {$MANUFACTURER} </td>";
        echo "\n\t<td align=left> {$UPC_CODE} </td>";
        echo "\n\t<td align=left> <a href='http://www.url.com/product.php?id={$SKU}'> Click Here </td>";
       
			 	echo "\n</tr>\n";
    }
    echo "\n</table>";
		echo "\n<table align=left>";
		echo "\n</tr>\n";
		echo "\n\t<td>This should be the bottom of the page</td>";
		echo "\n</tr>";
		echo "\n</table>";            
}
?>
 
</body>
</html>

Open in new window

0
TortugaAuthor Commented:
NerdsofTech, thanks for this, but don't know how to auto-generate an email once the nosku URL is clicked on.
Can you help me with that please?

Thanks!
0
NerdsOfTechTechnology ScientistCommented:
In http://www.url.com/product.php?SKU :


if (!isset($_GET["SKU"]) || $_GET["SKU"]==""){
 // redirect to emailer and form
}else{
 // original product.php code start
 
 
 
 
 // original product.php code finish
}

Open in new window

0
TortugaAuthor Commented:
Oh, what was wrong with your revised code? I was just about to give it a try.
0
NerdsOfTechTechnology ScientistCommented:
No problem just had to think of a better logic.
0
TortugaAuthor Commented:
Ah, sorry, let me explain.
I do not have rights to change anything in http://www.url.com/product.php?SKU.
All my application would do is point to a given item on www.url.com by SKU number.

So, any email generation that happens has to happen on my site, before the usr goes to http://www.url.com/product.php?SKU.

Is this possible?

Thanks.
0
NerdsOfTechTechnology ScientistCommented:
I added catalog to your link's GET string (querysring)

Now in http://www.url.com/product.php we will check SKU

If no SKU exists then we will use the CATALOG number to reference the missing SKU?

Okay ace?
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 
<html>
<head>
<title>Product Catalog</title>
</head>
<body background="" bgcolor="silver">
 
<?php
 
require 'pre_var.php';
 
if (!($connection = mysql_connect($hostname, $username, $password)))
{
    die("Could not connect");
}
if (!(mysql_select_db($databaseName, $connection)))
{
    showerror();
    die("Could not Select");
}
 
 
if (empty($_POST))
{
   $sql = "SELECT DISTINCT MANUFACTURER FROM main ORDER BY MANUFACTURER";
   $res = mysql_query($sql);
   if (!$res) die( mysql_error() );
   
	 echo "<table><tr><td>";
	 
	 echo "<form method=\"post\">\n";
   echo "Search by Manufacturer:<br />\n";
   echo "<select name=\"m\">\n";
   echo "<option>-Select Manufacturer-</option>";
       while ($row = mysql_fetch_assoc($res))
   {
       $m = $row["MANUFACTURER"];
       echo "<option>$m</option>\n";
   }
   echo "</select>\n";
   echo "<input value=\"Search\" type=\"submit\">\n";
   echo "</form>\n";
	 
	 echo "</td></tr>";
   echo "</tr><td>";
	 
	 echo "<form method=\"post\">\n";
   echo "Search by Part# or Description:<br />\n";
   echo "<input name=\"descript\" >\n";
   echo "<input name=\"searchExact\" value=\"Search exact\" type=\"submit\">\n";
   echo "<input name=\"searchLike\"  value=\"Search similar...\" type=\"submit\">\n";
   echo "<input type='radio' NAME='whichType' value='DESCRIPTION'> by Description";
   echo "<input type='radio' NAME='whichType' value='CATALOG' CHECKED> by Part#";
   echo "</form>\n";
	 
	 echo "</td></tr></table>";
} 
else
{
   $descript    = mysql_real_escape_string($_POST["descript"]);
   $searchExact = mysql_real_escape_string($_POST["searchExact"]);
   $searchLike  = mysql_real_escape_string($_POST["searchLike"]);
   $whichType   = mysql_real_escape_string($_POST["whichType"]);
   
   
   if($searchExact==='Search exact')
   {
      $query = "SELECT * FROM main WHERE $whichType = \"$descript\" ORDER BY MANUFACTURER, CATALOG";
   }
   elseif($searchLike==='Search similar...')
   {
      $query = "SELECT * FROM main WHERE $whichType LIKE \"%$descript%\" ORDER BY MANUFACTURER, CATALOG";
   }
   elseif(isset($_POST["m"]))
   {
      $m = mysql_real_escape_string($_POST["m"]);
      $query = "SELECT * FROM main WHERE MANUFACTURER = \"$m\" ORDER BY CATALOG";
   }
   if (!($result = mysql_query ($query, $connection)))
   {
       showerror();
       die("Query Error");
   }
   
   displayItems($result);
}
 
 
function displayItems($result)
{
    echo "<a href='javascript:history.back()'><< Back</a>";
    echo "<h2>Your Search Results:</h2>" ;
    echo "\n<table border=1 align=left>\n<tr>\n" .
       "\n\t<td><b>Catalog/Part#</b></td>" .
       "\n\t<td><b>Item Description</b></td>" .
       "\n\t<td><b>Manufacturer</b></td>" .
       "\n\t<td><b>UPC Code</b></td>" .
       "\n\t<td><b>Order Info</b></td>" .
       "\n</tr>";
    while ($row = mysql_fetch_assoc($result))
    {
   
        extract($row);
        echo "\n<tr>";
        echo "\n\t<td align=left> {$CATALOG} </td>";
        echo "\n\t<td align=left> {$DESCRIPTION} </td>";
        echo "\n\t<td align=left> {$MANUFACTURER} </td>";
        echo "\n\t<td align=left> {$UPC_CODE} </td>";
        echo "\n\t<td align=left> <a href='http://www.url.com/product.php?id={$SKU}&catalog={$CATALOG}'> Click Here </td>";
       
			 	echo "\n</tr>\n";
    }
    echo "\n</table>";
		echo "\n<table align=left>";
		echo "\n</tr>\n";
		echo "\n\t<td>This should be the bottom of the page</td>";
		echo "\n</tr>";
		echo "\n</table>";            
}
?>
 
</body>
</html>

Open in new window

0
NerdsOfTechTechnology ScientistCommented:
OH? you cant change product.php???
0
NerdsOfTechTechnology ScientistCommented:
Oh man, can you fully explain this process to me. I am lost now. I though you had control of both pages.
0
TortugaAuthor Commented:
Ok, so sorry..
This application will live on www.myurl.com

It pulls from a table where there are hundreds of thousands of items.

Some of these items are listed through www.anotherurl.com, and they have SKU numbers which correspond to SOME of those in the table at www.myurl.com.

So when a user searches for, and finds an item, clicks on it, IF it exists on anotherurl.com (has a SKU), then I want them to go through and view that items page (anotherurl.com/product.php...). But, if the item is one not listed (No SKU), then I want to be alerted of this (by email) and then later let the user contact me to let me know they are interested, want to buy, replacements, etc...

I can only make changes on myurl.com, not anotherurl.com.

Sorry to have been unclear, does this help?
0
TortugaAuthor Commented:
So, I guess in a nutshell, what this application will do is alert me when there is interest in a particular item that isn't yet active on anotherurl.com, since the email which is autogenerated will contain info like the manufacturer and part number.

I can then use that "interest data" to make a decision as to which items are popular and push to the live site.
0
NerdsOfTechTechnology ScientistCommented:
look at the link line change it to yours and the other url
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 
<html>
<head>
<title>Product Catalog</title>
</head>
<body background="" bgcolor="silver">
 
<?php
 
require 'pre_var.php';
 
if (!($connection = mysql_connect($hostname, $username, $password)))
{
    die("Could not connect");
}
if (!(mysql_select_db($databaseName, $connection)))
{
    showerror();
    die("Could not Select");
}
 
 
if (empty($_POST))
{
   $sql = "SELECT DISTINCT MANUFACTURER FROM main ORDER BY MANUFACTURER";
   $res = mysql_query($sql);
   if (!$res) die( mysql_error() );
   
         echo "<table><tr><td>";
         
         echo "<form method=\"post\">\n";
   echo "Search by Manufacturer:<br />\n";
   echo "<select name=\"m\">\n";
   echo "<option>-Select Manufacturer-</option>";
       while ($row = mysql_fetch_assoc($res))
   {
       $m = $row["MANUFACTURER"];
       echo "<option>$m</option>\n";
   }
   echo "</select>\n";
   echo "<input value=\"Search\" type=\"submit\">\n";
   echo "</form>\n";
         
         echo "</td></tr>";
   echo "</tr><td>";
         
         echo "<form method=\"post\">\n";
   echo "Search by Part# or Description:<br />\n";
   echo "<input name=\"descript\" >\n";
   echo "<input name=\"searchExact\" value=\"Search exact\" type=\"submit\">\n";
   echo "<input name=\"searchLike\"  value=\"Search similar...\" type=\"submit\">\n";
   echo "<input type='radio' NAME='whichType' value='DESCRIPTION'> by Description";
   echo "<input type='radio' NAME='whichType' value='CATALOG' CHECKED> by Part#";
   echo "</form>\n";
         
         echo "</td></tr></table>";
} 
else
{
   $descript    = mysql_real_escape_string($_POST["descript"]);
   $searchExact = mysql_real_escape_string($_POST["searchExact"]);
   $searchLike  = mysql_real_escape_string($_POST["searchLike"]);
   $whichType   = mysql_real_escape_string($_POST["whichType"]);
   
   
   if($searchExact==='Search exact')
   {
      $query = "SELECT * FROM main WHERE $whichType = \"$descript\" ORDER BY MANUFACTURER, CATALOG";
   }
   elseif($searchLike==='Search similar...')
   {
      $query = "SELECT * FROM main WHERE $whichType LIKE \"%$descript%\" ORDER BY MANUFACTURER, CATALOG";
   }
   elseif(isset($_POST["m"]))
   {
      $m = mysql_real_escape_string($_POST["m"]);
      $query = "SELECT * FROM main WHERE MANUFACTURER = \"$m\" ORDER BY CATALOG";
   }
   if (!($result = mysql_query ($query, $connection)))
   {
       showerror();
       die("Query Error");
   }
   
   displayItems($result);
}
 
 
function displayItems($result)
{
                echo "<a href='javascript:history.back()'><< Back</a>";
    echo "<h2>Your Search Results:</h2>" ;
    echo "\n<table border=1 align=left>\n<tr>\n" .
       "\n\t<td><b>Catalog/Part#</b></td>" .
       "\n\t<td><b>Item Description</b></td>" .
       "\n\t<td><b>Manufacturer</b></td>" .
       "\n\t<td><b>UPC Code</b></td>" .
       "\n\t<td><b>Order Info</b></td>" .
       "\n</tr>";
    while ($row = mysql_fetch_assoc($result))
    {
   
        extract($row);
        echo "\n<tr>";
        echo "\n\t<td align=left> {$CATALOG} </td>";
        echo "\n\t<td align=left> {$DESCRIPTION} </td>";
        echo "\n\t<td align=left> {$MANUFACTURER} </td>";
        echo "\n\t<td align=left> {$UPC_CODE} </td>";
        echo "\n\t<td align=left> " . ($SKU <> "" ? "<a href='http://www.anotherurl.com/product.php?id={$SKU}'> Click Here </a></td>" : "<a href='http://www.myurl.com/nosku.php'>Click Here</a></td>");
       
                                echo "\n</tr>\n";
    }
    echo "\n</table>";
                echo "\n<table align=left>";
                echo "\n</tr>\n";
                echo "\n\t<td>This should be the bottom of the page</td>";
                echo "\n</tr>";
                echo "\n</table>";            
}
?>
 
</body>
</html>

Open in new window

0
NerdsOfTechTechnology ScientistCommented:
HERE USE THIS instead: This will pass the CATALOG number to the nosku.php so you can figure out which item they are interested in.
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 
<html>
<head>
<title>Product Catalog</title>
</head>
<body background="" bgcolor="silver">
 
<?php
 
require 'pre_var.php';
 
if (!($connection = mysql_connect($hostname, $username, $password)))
{
    die("Could not connect");
}
if (!(mysql_select_db($databaseName, $connection)))
{
    showerror();
    die("Could not Select");
}
 
 
if (empty($_POST))
{
   $sql = "SELECT DISTINCT MANUFACTURER FROM main ORDER BY MANUFACTURER";
   $res = mysql_query($sql);
   if (!$res) die( mysql_error() );
   
         echo "<table><tr><td>";
         
         echo "<form method=\"post\">\n";
   echo "Search by Manufacturer:<br />\n";
   echo "<select name=\"m\">\n";
   echo "<option>-Select Manufacturer-</option>";
       while ($row = mysql_fetch_assoc($res))
   {
       $m = $row["MANUFACTURER"];
       echo "<option>$m</option>\n";
   }
   echo "</select>\n";
   echo "<input value=\"Search\" type=\"submit\">\n";
   echo "</form>\n";
         
         echo "</td></tr>";
   echo "</tr><td>";
         
         echo "<form method=\"post\">\n";
   echo "Search by Part# or Description:<br />\n";
   echo "<input name=\"descript\" >\n";
   echo "<input name=\"searchExact\" value=\"Search exact\" type=\"submit\">\n";
   echo "<input name=\"searchLike\"  value=\"Search similar...\" type=\"submit\">\n";
   echo "<input type='radio' NAME='whichType' value='DESCRIPTION'> by Description";
   echo "<input type='radio' NAME='whichType' value='CATALOG' CHECKED> by Part#";
   echo "</form>\n";
         
         echo "</td></tr></table>";
} 
else
{
   $descript    = mysql_real_escape_string($_POST["descript"]);
   $searchExact = mysql_real_escape_string($_POST["searchExact"]);
   $searchLike  = mysql_real_escape_string($_POST["searchLike"]);
   $whichType   = mysql_real_escape_string($_POST["whichType"]);
   
   
   if($searchExact==='Search exact')
   {
      $query = "SELECT * FROM main WHERE $whichType = \"$descript\" ORDER BY MANUFACTURER, CATALOG";
   }
   elseif($searchLike==='Search similar...')
   {
      $query = "SELECT * FROM main WHERE $whichType LIKE \"%$descript%\" ORDER BY MANUFACTURER, CATALOG";
   }
   elseif(isset($_POST["m"]))
   {
      $m = mysql_real_escape_string($_POST["m"]);
      $query = "SELECT * FROM main WHERE MANUFACTURER = \"$m\" ORDER BY CATALOG";
   }
   if (!($result = mysql_query ($query, $connection)))
   {
       showerror();
       die("Query Error");
   }
   
   displayItems($result);
}
 
 
function displayItems($result)
{
                echo "<a href='javascript:history.back()'><< Back</a>";
    echo "<h2>Your Search Results:</h2>" ;
    echo "\n<table border=1 align=left>\n<tr>\n" .
       "\n\t<td><b>Catalog/Part#</b></td>" .
       "\n\t<td><b>Item Description</b></td>" .
       "\n\t<td><b>Manufacturer</b></td>" .
       "\n\t<td><b>UPC Code</b></td>" .
       "\n\t<td><b>Order Info</b></td>" .
       "\n</tr>";
    while ($row = mysql_fetch_assoc($result))
    {
   
        extract($row);
        echo "\n<tr>";
        echo "\n\t<td align=left> {$CATALOG} </td>";
        echo "\n\t<td align=left> {$DESCRIPTION} </td>";
        echo "\n\t<td align=left> {$MANUFACTURER} </td>";
        echo "\n\t<td align=left> {$UPC_CODE} </td>";
        echo "\n\t<td align=left> " . ($SKU <> "" ? "<a href='http://www.anotherurl.com/product.php?id={$SKU}'> Click Here </a></td>" : "<a href='http://www.myurl.com/nosku.php?catalog={$CATALOG}'>Click Here</a></td>");
       
                                echo "\n</tr>\n";
    }
    echo "\n</table>";
                echo "\n<table align=left>";
                echo "\n</tr>\n";
                echo "\n\t<td>This should be the bottom of the page</td>";
                echo "\n</tr>";
                echo "\n</table>";            
}
?>
 
</body>
</html>

Open in new window

0
NerdsOfTechTechnology ScientistCommented:
Then make a new page on your site called nosku.php and correct the fields below:
<?php
 
// nosku.php
 
if (isset($_GET["CATALOG"]) && $_GET["CATALOG"] != ""){
 // send email
 $catalog = $_GET['catalog'];
 // do some format stuff to the form input avoid hacking here
 
 $to      = 'you@myurl.com';
 $subject = 'Somebody clicked on a blank sku product!';
 $message = 'Catalog #: ' . $catalog;
 $headers = 'From: you@myurl.com' . "\r\n" .
            'Reply-To: you@myurl.com' . "\r\n" .
            'X-Mailer: PHP/' . phpversion();
 
 mail($to, $subject, $message, $headers);
 
 //redirect user to form
 header('Location: userform.php');
}else{
 echo 'Access Denied';
}
?>

Open in new window

0
NerdsOfTechTechnology ScientistCommented:
Then finally make a page called userform.php for your form.
0
NerdsOfTechTechnology ScientistCommented:
Mission complete.
0
TortugaAuthor Commented:
looks golden.
I'll try it out when I get in to work. Maybe 2 hours.
Thanks for your efforts!
0
TortugaAuthor Commented:
//redirect user to form
 header('Location: userform.php');
}else{
 echo 'Access Denied';
}

I made a php file called userform.php, but I still get "Access Denied".
And, no email is sent to me. Ive tried this a couple times.

Also, can I pas the $manufacturer into the nosku email as well?
0
TortugaAuthor Commented:
So, the NOSKU page seems to have a problem.
0
NerdsOfTechTechnology ScientistCommented:
oops in nosku.php I made the get variable CATALOG in all caps accidentally :)

first, here is the product page with the new link that includes the catalogID and the manufacturer
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
 
<html>
<head>
<title>Product Catalog</title>
</head>
<body background="" bgcolor="silver">
 
<?php
// catalog page 
require 'pre_var.php';
 
if (!($connection = mysql_connect($hostname, $username, $password)))
{
    die("Could not connect");
}
if (!(mysql_select_db($databaseName, $connection)))
{
    showerror();
    die("Could not Select");
}
 
 
if (empty($_POST))
{
   $sql = "SELECT DISTINCT MANUFACTURER FROM main ORDER BY MANUFACTURER";
   $res = mysql_query($sql);
   if (!$res) die( mysql_error() );
   
         echo "<table><tr><td>";
         
         echo "<form method=\"post\">\n";
   echo "Search by Manufacturer:<br />\n";
   echo "<select name=\"m\">\n";
   echo "<option>-Select Manufacturer-</option>";
       while ($row = mysql_fetch_assoc($res))
   {
       $m = $row["MANUFACTURER"];
       echo "<option>$m</option>\n";
   }
   echo "</select>\n";
   echo "<input value=\"Search\" type=\"submit\">\n";
   echo "</form>\n";
         
         echo "</td></tr>";
   echo "</tr><td>";
         
         echo "<form method=\"post\">\n";
   echo "Search by Part# or Description:<br />\n";
   echo "<input name=\"descript\" >\n";
   echo "<input name=\"searchExact\" value=\"Search exact\" type=\"submit\">\n";
   echo "<input name=\"searchLike\"  value=\"Search similar...\" type=\"submit\">\n";
   echo "<input type='radio' NAME='whichType' value='DESCRIPTION'> by Description";
   echo "<input type='radio' NAME='whichType' value='CATALOG' CHECKED> by Part#";
   echo "</form>\n";
         
         echo "</td></tr></table>";
} 
else
{
   $descript    = mysql_real_escape_string($_POST["descript"]);
   $searchExact = mysql_real_escape_string($_POST["searchExact"]);
   $searchLike  = mysql_real_escape_string($_POST["searchLike"]);
   $whichType   = mysql_real_escape_string($_POST["whichType"]);
   
   
   if($searchExact==='Search exact')
   {
      $query = "SELECT * FROM main WHERE $whichType = \"$descript\" ORDER BY MANUFACTURER, CATALOG";
   }
   elseif($searchLike==='Search similar...')
   {
      $query = "SELECT * FROM main WHERE $whichType LIKE \"%$descript%\" ORDER BY MANUFACTURER, CATALOG";
   }
   elseif(isset($_POST["m"]))
   {
      $m = mysql_real_escape_string($_POST["m"]);
      $query = "SELECT * FROM main WHERE MANUFACTURER = \"$m\" ORDER BY CATALOG";
   }
   if (!($result = mysql_query ($query, $connection)))
   {
       showerror();
       die("Query Error");
   }
   
   displayItems($result);
}
 
 
function displayItems($result)
{
                echo "<a href='javascript:history.back()'><< Back</a>";
    echo "<h2>Your Search Results:</h2>" ;
    echo "\n<table border=1 align=left>\n<tr>\n" .
       "\n\t<td><b>Catalog/Part#</b></td>" .
       "\n\t<td><b>Item Description</b></td>" .
       "\n\t<td><b>Manufacturer</b></td>" .
       "\n\t<td><b>UPC Code</b></td>" .
       "\n\t<td><b>Order Info</b></td>" .
       "\n</tr>";
    while ($row = mysql_fetch_assoc($result))
    {
   
        extract($row);
        echo "\n<tr>";
        echo "\n\t<td align=left> {$CATALOG} </td>";
        echo "\n\t<td align=left> {$DESCRIPTION} </td>";
        echo "\n\t<td align=left> {$MANUFACTURER} </td>";
        echo "\n\t<td align=left> {$UPC_CODE} </td>";
        echo "\n\t<td align=left> " . ($SKU <> "" ? "<a href='http://www.anotherurl.com/product.php?id={$SKU}'> Click Here </a></td>" : "<a href='http://www.myurl.com/nosku.php?catalog={$CATALOG}&manufacturer={$MANUFACTURER}A'>Click Here</a></td>");
       
                                echo "\n</tr>\n";
    }
    echo "\n</table>";
                echo "\n<table align=left>";
                echo "\n</tr>\n";
                echo "\n\t<td>This should be the bottom of the page</td>";
                echo "\n</tr>";
                echo "\n</table>";            
}
?>
 
</body>
</html>

Open in new window

0
NerdsOfTechTechnology ScientistCommented:
Here's the fixed nosku:

Also I added the manufacturer in the email besides the catalog id.

The email function is only is requiring the catalog as the input to start the email.


<?php
 
// nosku.php
 
if (isset($_GET["catalog"]) && $_GET["catalog"] != ""){
 // send email
 $catalog = $_GET['catalog'];
 $manufacturer = $GET['manufacturer'];
 // do some format stuff to the form input avoid hacking here
 
 $to      = 'you@myurl.com';
 $subject = 'Somebody clicked on a blank sku product!';
 $message = 'Catalog #: ' . $catalog; . ', Manufacturer: ' . $manufacturer '.';
 $headers = 'From: you@myurl.com' . "\r\n" .
            'Reply-To: you@myurl.com' . "\r\n" .
            'X-Mailer: PHP/' . phpversion();
 
 mail($to, $subject, $message, $headers);
 
 //redirect user to form
 header('Location: userform.php');
}else{
 // echo 'Access Denied';
 // redirect and pass error code 1. no catalogID found.
 header('Location: userform.php?e=1');
}
?>

Open in new window

0
TortugaAuthor Commented:
Ok, GREAT!
So, I first got an error, on line 13, an unexpected "."
Now, I have this as line 13:
$message = 'Catalog #: ' . $catalog . ', Manufacturer: ' . $manufacturer ;

and it generates an email, and its great. However, the Manufacturer value doesnt print, but "Manufacturer:" does. Did I leave some proper syntax out of this line?

Thanks again!
0
NerdsOfTechTechnology ScientistCommented:
missing a "." . my error :)

Fixed!
<?php
 
// nosku.php
 
if (isset($_GET["catalog"]) && $_GET["catalog"] != ""){
 // send email
 $catalog = $_GET['catalog'];
 $manufacturer = $GET['manufacturer'];
 // do some format stuff to the form input avoid hacking here
 
 $to      = 'you@myurl.com';
 $subject = 'Somebody clicked on a blank sku product!';
 $message = 'Catalog #: ' . $catalog; . ', Manufacturer: ' . $manufacturer . '.';
 $headers = 'From: you@myurl.com' . "\r\n" .
            'Reply-To: you@myurl.com' . "\r\n" .
            'X-Mailer: PHP/' . phpversion();
 
 mail($to, $subject, $message, $headers);
 
 //redirect user to form
 header('Location: userform.php');
}else{
 // echo 'Access Denied';
 // redirect and pass error code 1. no catalogID found.
 header('Location: userform.php?e=1');
}
?>

Open in new window

0
TortugaAuthor Commented:
Parse error: syntax error, unexpected '.' in /home/genode/public_html/wiringdevice/nosku.php on line 13
0
TortugaAuthor Commented:
I think there were one too many to begin with, then I got rid of one and posted my new line above. Your last revision I think reverted to what you originally posted.

The line I edited generated an email, but wihtout the MANUFACTURER value.
0
NerdsOfTechTechnology ScientistCommented:
Oops! $_GET line 8. FIXED!
<?php
 
// nosku.php
 
if (isset($_GET["catalog"]) && $_GET["catalog"] != ""){
 // send email
 $catalog = $_GET['catalog'];
 $manufacturer = $_GET['manufacturer'];
 // do some format stuff to the form input avoid hacking here
 
 $to      = 'you@myurl.com';
 $subject = 'Somebody clicked on a blank sku product!';
 $message = 'Catalog #: ' . $catalog; . ', Manufacturer: ' . $manufacturer . '.';
 $headers = 'From: you@myurl.com' . "\r\n" .
            'Reply-To: you@myurl.com' . "\r\n" .
            'X-Mailer: PHP/' . phpversion();
 
 mail($to, $subject, $message, $headers);
 
 //redirect user to form
 header('Location: userform.php');
}else{
 // echo 'Access Denied';
 // redirect and pass error code 1. no catalogID found.
 header('Location: userform.php?e=1');
}
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
TortugaAuthor Commented:
Line 13: $message = 'Catalog #: ' . $catalog . ', Manufacturer: ' . $manufacturer;
gives me an email like this: Catalog #: 304C04B, Manufacturer:

Note: I edited this line from what you posted above, I kept getting unexpected "." errors.
Weird that it doesnt grab the manufacturer value.
0
TortugaAuthor Commented:
Ah, I am a fool... I didnt update the original code to pas the manufacturer variable.
ok, this is almost done, now I just need to make the little email collector form.
Can I post that here for you to just double check?

Also, I tried adding a "Your search returned XXX results", but I dont know where to declare the $num_rows = mysql_num_rows($result);

Then I put it in a "while" but it keep looping interminably.

I just need a little message at the top of the result table.

Thanks, you are the best!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.