Hi David, hope all is well.
I have created this table in my database:
{code saved}
And added this line in the html/related.php
<div class="issue">###.com works hard to improve your online shopping experience every day.
<br />If you notice inconsistencies in our product information,
<br />
we encourage you to notify us of any issues by
<a href='<?php print $config_baseHREF."report-product-issue.php?id=".$mainProduct["id"]; ?>'><strong>clicking here.</strong></a></div>
And I have this as report-product-issue.php in the install directory.
{code saved}
And I have a few issues with my script...so here goes.
#1 How to pull in the actual lowest price of the product.
#2 How to make the merchant field populated with a dropdown select box with all the merchants that have said product.
#3 Is how to check that a valid email format is supplied and not NULL.
And last but not least.
#4 I had this problem before, line #70 headers already sent....tried moving it around didn't work. :(
Bob L.
Thank you David.
Everything work worked I believe except nothing got inserted into the table.
I checked the sequence of changes 3 time.
drop down works fine, redirect works fine, and no header messages.
??
Hello Bob,
If you enable database debug mode by changing line 6 in config.advanced.php as follows;
$config_databaseDebugMode = TRUE;
...that should indicate the reason for no record being inserted; but I did just notice in the code that "INTO" is missing from the SQL - the line should be:
$sql = "INSERT INTO `".$config_databaseTablePrefix."productissue` (`id`, `pid`, `name`, `brand`, `price`, `merchant`, `category`, `issue`, `email`, `comment`, `timestamp`) VALUES (NULL,'$id', '".database_safe($name)."', '".database_safe($brand)."', '".database_safe($price)."', '".database_safe($merchant)."', '".database_safe($category)."', '".database_safe($issue)."', '".database_safe($email)."', '".database_safe($comment)."', CURRENT_TIMESTAMP) ";
...so that may be all it is but if not, database debug mode should reveal the problem with the actual MySQL error message...
Cheers,
David.
--
PriceTapestry.com
Hi Bob,
Re: #1
The main $row that you select derived from $mainProduct["id"] in the referring script will be the row that contains the lowest price of the product since $mainProduct is created from the first record in the $product["products"] array which is sorted in ascending price order.
Re: #2
To make your merchant input a drop-down of all merchants selling the product; in place of
print $merchant;
...have a go with:
$sql = "SELECT merchant FROM `".$config_databaseTablePrefix."products` WHERE name='".database_safe($rows[0]["name"])."' ORDER BY merchant";
database_querySelect($sql,$merchants);
print "<select name='merchant'>";
foreach($merchants as $merchant)
{
print "<option value='".htmlentities($merchant["merchant"],ENT_QUOTES)."'>".$merchant["merchant"]."</option>";
}
print "</select>";
Re: #3,#4
Considering the following block of code from the end of your script:
$submit = (isset($_POST["submit"])?$_POST["submit"]:"");
if ($submit == "Cancel")
{
header("Location: index.php");
exit();
}
if ($submit == "Submit"){
$issue = $_POST['issue'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$sql = "INSERT `".$config_databaseTablePrefix."productissue` (`id`, `pid`, `name`, `brand`, `price`, `merchant`, `category`, `issue`, `email`, `comment`, `timestamp`) VALUES (NULL,'$id', '$name', '$brand', '$price', '$merchant', '$category', '$issue', '$email', '$comment', CURRENT_TIMESTAMP) ";
database_queryModify($sql,$insertId);
header("Location: index.php");
}
This needs to be moved to above the point at which the header begins, as this is where headers become send and you can no longer use the location() function to redirect the page. However, because this section of the script relies upon the select query performed earlier, that too must be moved above the form handler code; so combining with the form handler code, have a go with:
function validate_email($email)
{
if (eregi("^[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]{2,6}$", $email, $check))
{
return true;
}
return false;
}
$sql = "SELECT * FROM `".$config_databaseTablePrefix."products` WHERE `id` = '".database_safe($q)."'";
$numRows = database_querySelect($sql,$rows);
$submit = (isset($_POST["submit"])?$_POST["submit"]:"");
if ($submit == "Cancel")
{
header("Location: index.php");
exit();
}
if ($submit == "Submit" && validate_email($_POST['email'])){
$issue = $_POST['issue'];
$email = $_POST['email'];
$comment = $_POST['comment'];
$sql = "INSERT `".$config_databaseTablePrefix."productissue` (`id`, `pid`, `name`, `brand`, `price`, `merchant`, `category`, `issue`, `email`, `comment`, `timestamp`) VALUES (NULL,'$id', '".database_safe($name)."', '".database_safe($brand)."', '".database_safe($price)."', '".database_safe($merchant)."', '".database_safe($category)."', '".database_safe($issue)."', '".database_safe($email)."', '".database_safe($comment)."', CURRENT_TIMESTAMP) ";
database_queryModify($sql,$insertId);
header("Location: index.php");
}
...inserted immediately _BEFORE_ the following line:
require("html/header.php");
I added a validate_email function, and also database_safe() calls around all the parameters being used to construct your report SQL...
Hope this helps!
Cheers,
David.
--
PriceTapestry.com