Hi
Posted: Sun Oct 12, 2008 7:34 pm
Hi im new to your forums. and was having a problem with some code im writing for a database.
im trying to run a search on a database using keywords that have been entered into the database.
my tables are as follow:
Coupons <-- Main database
CouponSearchTerms <-- Links Coupons and CouponTerms
CouponSources <-- Table used to tell where the Coupon came from
CouponTerms <-- where the keywords are stored
so far i have this as my entry page:
<?php
include_once "opendb.php";
?>
<form method="post" name="Coupondatabse">
<table width="550" border="0" cellpadding="2" cellspacing="1">
<tr>
<td width="100">Coupon:</td>
<td>
<input name="txtCoupon" type="text" size="30"></td>
</tr>
<p>
<tr>
<td width="100">Source:</td>
<td>
<p> </p>
<p>Source ID numbers:</p>
<p>1. Smart Source</p>
<p>2. Red Plum</p>
<p>3. Publix</p>
<p>4. General Mills</p>
<p>5. Procter & Gamble</p>
<p>6. Kelloggs</p>
<p>
<input name="txtSource" type="text" size="30" />
</p></td>
</tr>
<tr>
<td width="100">Publish Date</td>
<td>
<input name="txtReleaseDate" type="text" size="30"></td>
</tr>
<p>
<tr>
<td width="100">Expires On:</td>
<td>
<p>
<input name="txtExpiresOn" type="text" size="30">
</p>
</td>
</tr>
<p>
<tr>
<td width="100">Value</td>
<td>
<input name="txtValue" type="text" size="30"></td>
</tr>
<tr>
<td width="100">Search Tags</td>
<td>
<input name="txtMetatag" type="text" size="30" /></td>
</tr>
<tr>
<td width="100"> </td>
<td>
<input name="btnAdd" type="submit" value="Add Coupon" onClick="return checkForm();"></td>
</tr>
</table>
<?php
include 'connection.php';
include 'opendb.php';
if(isset($_POST['btnAdd']))
{
$con = mysql_connect("localhost","grocerie_coupons","*********");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("grocerie_coupons", $con);
$Coupon_offer = trim($_POST['txtCoupon']);
$Coupon_source_ID = trim($_POST['txtSource']);
$Expires_on = trim($_POST['txtExpiresOn']);
$Release_Date = trim($_POST['txtReleaseDate']);
$value = trim($_POST['txtValue']);
$Word = trim($_POST['txtMetatag']);
$query = "INSERT INTO Coupons (Coupon_offer, Coupon_source_ID,Release_Date, Expires_on, value)
VALUES ('$Coupon_offer', '$Coupon_source_ID', '$Release_Date', '$Expires_on','$value')";
$query = "INSERT INTO SearchTerms (Word)
VALUES ('$Word')";
mysql_query($query) or die('Error, query failed');
header('Location: ' . $_SERVER['REQUEST_URI']);
exit;
}
?>
</body>
</html>
the code in red is whats putting the keywords into my database. also, only one word can be entered at a time, is there a way to fix it?
my search page has the following code:
<?php
include_once "opendb.php";
?>
<form name="CouponSearch" action = "<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table width="550" border="0" cellpadding="2" cellspacing="1">
<tr>
<td width="100">Search</td>
<td><input name="txtSearch" type="text" size="30" value="<?php if (isset($_POST['txtSearch'])) { echo $_POST['txtSearch']; } else { echo '';} ?>" /></td>
</tr>
<?php
/* $words = $_POST['txtSearch'];
$tok = strtok($words, " " . ",");
while ($tok !== false) {
echo "$tok<br />";
$tok = strtok(" " . ",");
} */
?>
<tr>
<td width="100"> </td>
<td><p class="submit"> <input name="btnSearch" type="submit" value="Search" /></td>
</p>
</tr>
</table>
</form>
</body>
<html>
<?php
if(isset($_POST['btnSearch'])) {
$query = "SELECT `Coupon_offer`, `Release_Date`, `Expires_on`, `Value`, `Source` FROM `Coupons`, `CouponSources` where `Coupons`.`Coupon_source_ID` = `CouponSources`.`ID`";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result) == 0) { ?>
<p><br>
<br>
Database is empty</p>
<?php } else {
echo "<table width=\"100%\" cellspacing=\"0\" border=\"1\" cellpadding=\"2\">\n";
while($row = mysql_fetch_array($result)) {
$tablerow = "<tr><td>" . $row['Coupon_offer'] . "</td><td align=\"center\">" . $row['Release_Date'] . "</td><td align=\"center\">" . $row['Expires_on'] . "</td><td align=\"right\">" . sprintf("$%01.2f", $row['Value']);
$tablerow.= "</td><td>" . $row['Source'] . "</td></tr>\n";
echo $tablerow;
}
echo "</table>\n";
}
}
?>
</td>
</tr>
</table>
its in this code im thinking that i put the $query to select only the Coupons that meet the keywords searched for. each Coupon and CouponTerms is set to auto incrament ID
Thanks in advance, not sure if its even possible but if it is thanks
im trying to run a search on a database using keywords that have been entered into the database.
my tables are as follow:
Coupons <-- Main database
CouponSearchTerms <-- Links Coupons and CouponTerms
CouponSources <-- Table used to tell where the Coupon came from
CouponTerms <-- where the keywords are stored
so far i have this as my entry page:
<?php
include_once "opendb.php";
?>
<form method="post" name="Coupondatabse">
<table width="550" border="0" cellpadding="2" cellspacing="1">
<tr>
<td width="100">Coupon:</td>
<td>
<input name="txtCoupon" type="text" size="30"></td>
</tr>
<p>
<tr>
<td width="100">Source:</td>
<td>
<p> </p>
<p>Source ID numbers:</p>
<p>1. Smart Source</p>
<p>2. Red Plum</p>
<p>3. Publix</p>
<p>4. General Mills</p>
<p>5. Procter & Gamble</p>
<p>6. Kelloggs</p>
<p>
<input name="txtSource" type="text" size="30" />
</p></td>
</tr>
<tr>
<td width="100">Publish Date</td>
<td>
<input name="txtReleaseDate" type="text" size="30"></td>
</tr>
<p>
<tr>
<td width="100">Expires On:</td>
<td>
<p>
<input name="txtExpiresOn" type="text" size="30">
</p>
</td>
</tr>
<p>
<tr>
<td width="100">Value</td>
<td>
<input name="txtValue" type="text" size="30"></td>
</tr>
<tr>
<td width="100">Search Tags</td>
<td>
<input name="txtMetatag" type="text" size="30" /></td>
</tr>
<tr>
<td width="100"> </td>
<td>
<input name="btnAdd" type="submit" value="Add Coupon" onClick="return checkForm();"></td>
</tr>
</table>
<?php
include 'connection.php';
include 'opendb.php';
if(isset($_POST['btnAdd']))
{
$con = mysql_connect("localhost","grocerie_coupons","*********");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("grocerie_coupons", $con);
$Coupon_offer = trim($_POST['txtCoupon']);
$Coupon_source_ID = trim($_POST['txtSource']);
$Expires_on = trim($_POST['txtExpiresOn']);
$Release_Date = trim($_POST['txtReleaseDate']);
$value = trim($_POST['txtValue']);
$Word = trim($_POST['txtMetatag']);
$query = "INSERT INTO Coupons (Coupon_offer, Coupon_source_ID,Release_Date, Expires_on, value)
VALUES ('$Coupon_offer', '$Coupon_source_ID', '$Release_Date', '$Expires_on','$value')";
$query = "INSERT INTO SearchTerms (Word)
VALUES ('$Word')";
mysql_query($query) or die('Error, query failed');
header('Location: ' . $_SERVER['REQUEST_URI']);
exit;
}
?>
</body>
</html>
the code in red is whats putting the keywords into my database. also, only one word can be entered at a time, is there a way to fix it?
my search page has the following code:
<?php
include_once "opendb.php";
?>
<form name="CouponSearch" action = "<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table width="550" border="0" cellpadding="2" cellspacing="1">
<tr>
<td width="100">Search</td>
<td><input name="txtSearch" type="text" size="30" value="<?php if (isset($_POST['txtSearch'])) { echo $_POST['txtSearch']; } else { echo '';} ?>" /></td>
</tr>
<?php
/* $words = $_POST['txtSearch'];
$tok = strtok($words, " " . ",");
while ($tok !== false) {
echo "$tok<br />";
$tok = strtok(" " . ",");
} */
?>
<tr>
<td width="100"> </td>
<td><p class="submit"> <input name="btnSearch" type="submit" value="Search" /></td>
</p>
</tr>
</table>
</form>
</body>
<html>
<?php
if(isset($_POST['btnSearch'])) {
$query = "SELECT `Coupon_offer`, `Release_Date`, `Expires_on`, `Value`, `Source` FROM `Coupons`, `CouponSources` where `Coupons`.`Coupon_source_ID` = `CouponSources`.`ID`";
$result = mysql_query($query) or die('Error, query failed');
if(mysql_num_rows($result) == 0) { ?>
<p><br>
<br>
Database is empty</p>
<?php } else {
echo "<table width=\"100%\" cellspacing=\"0\" border=\"1\" cellpadding=\"2\">\n";
while($row = mysql_fetch_array($result)) {
$tablerow = "<tr><td>" . $row['Coupon_offer'] . "</td><td align=\"center\">" . $row['Release_Date'] . "</td><td align=\"center\">" . $row['Expires_on'] . "</td><td align=\"right\">" . sprintf("$%01.2f", $row['Value']);
$tablerow.= "</td><td>" . $row['Source'] . "</td></tr>\n";
echo $tablerow;
}
echo "</table>\n";
}
}
?>
</td>
</tr>
</table>
its in this code im thinking that i put the $query to select only the Coupons that meet the keywords searched for. each Coupon and CouponTerms is set to auto incrament ID
Thanks in advance, not sure if its even possible but if it is thanks