Errors with SEARCH form select criteria into Mysql
Moderator: General Moderators
-
jamessirleaf
- Forum Newbie
- Posts: 8
- Joined: Tue Apr 13, 2004 7:24 am
- Location: Reading, UK
Errors with SEARCH form select criteria into Mysql
I am trying to get all of my form select criteria used in my sql query
Say I have a Mysql Database called Products. The options for products
in my form:
<form method ="post" action="database.php">
<select>
<selected> * </>
<option> Perfumes</option>
<option>Soap</option>
My select statement is "Select " "$select" from Products" .
The object is to be able to select and display only the soap criteria
if I want. Or, select and display only the Perfumes criteria if I want.
What I am getting, is
a). full details of all options with "*" selected. - Correct!
b). an error message prompting error with mysql__num_res or the
results of the query when I select "Perfumes".
c). Same error message as (b) above when I select "Soap".
Is there a way around this. I recon that MySQL should
render my form "select" criteria valid in its select statement.
Does anyone have any idea?
Regards,
James
Say I have a Mysql Database called Products. The options for products
in my form:
<form method ="post" action="database.php">
<select>
<selected> * </>
<option> Perfumes</option>
<option>Soap</option>
My select statement is "Select " "$select" from Products" .
The object is to be able to select and display only the soap criteria
if I want. Or, select and display only the Perfumes criteria if I want.
What I am getting, is
a). full details of all options with "*" selected. - Correct!
b). an error message prompting error with mysql__num_res or the
results of the query when I select "Perfumes".
c). Same error message as (b) above when I select "Soap".
Is there a way around this. I recon that MySQL should
render my form "select" criteria valid in its select statement.
Does anyone have any idea?
Regards,
James
-
jamessirleaf
- Forum Newbie
- Posts: 8
- Joined: Tue Apr 13, 2004 7:24 am
- Location: Reading, UK
-
jamessirleaf
- Forum Newbie
- Posts: 8
- Joined: Tue Apr 13, 2004 7:24 am
- Location: Reading, UK
The Mysql database is valid and consists of the following;
id -int
cat_id - 2
item_title - Skincare
List_1 - GiftBag
List_2 - Lip-Balm
List_3 - Body Wash
id
cat_id -3
item_title -Honey & Blackseed
List_1 -Honey & Blackseed Giftbag
List-2 -not yet declared
List_3 -not yet declared
id
cat_id -4
item_title - Lavendar & Wildflowers
List_1 - Lavendar & Wildflowes Giftbag
List_2 - not yet declared
List_3 - not yet declared
note* Each of these items under their respective item_titles(s) are treated as a separate row. (I have only replaced the perfumes and soap listings
with Skincare, Honey & Blackseed and Lavendar & Wildflowers.
The Form Element calls for the following:
<form method="post" action="database.php"
<select name =<"select">
<option selected ="selected>*</option">
<option>Skincare</option>
<option>Honey & Blackseed</option>
<option>Lavendar & Wildflowers</option>
</select>
<input type ="submit" value="search"
</form>
The action demanded is in the file database.php.
$conn=mysql_connect("localhost");
mysql_select_db("Products",$conn);
$get_iteminfo ="SELECT".$select."from products";
$result=mysql_query($get_iteminfo);
for $counter=0;
$row=mysql_fetch_row($result);
$counter++ {
print ("<tr>");
foreach ($row as $key=>$value)
print("<td>$value</td>");
}
</table>
<?php print ("$counter") ?> results.
</body>
</html>
This is the entire script for the most part. When my select
criteria is "*", I get a display of all of the results on a
row by row basis. The display also shows "not yet declared"
for columns where no item is placed yet.
I believe that my problem is with the call to the Mysql database.
I am hoping that the .$select. criteria will pick up the
appropriate selected choice from the form.
Hope this is clearer than my previous posting.
James
i.e. Skincare |Giftbag |Lipbalm
Honey & Blackseed |Giftbag
id -int
cat_id - 2
item_title - Skincare
List_1 - GiftBag
List_2 - Lip-Balm
List_3 - Body Wash
id
cat_id -3
item_title -Honey & Blackseed
List_1 -Honey & Blackseed Giftbag
List-2 -not yet declared
List_3 -not yet declared
id
cat_id -4
item_title - Lavendar & Wildflowers
List_1 - Lavendar & Wildflowes Giftbag
List_2 - not yet declared
List_3 - not yet declared
note* Each of these items under their respective item_titles(s) are treated as a separate row. (I have only replaced the perfumes and soap listings
with Skincare, Honey & Blackseed and Lavendar & Wildflowers.
The Form Element calls for the following:
<form method="post" action="database.php"
<select name =<"select">
<option selected ="selected>*</option">
<option>Skincare</option>
<option>Honey & Blackseed</option>
<option>Lavendar & Wildflowers</option>
</select>
<input type ="submit" value="search"
</form>
The action demanded is in the file database.php.
$conn=mysql_connect("localhost");
mysql_select_db("Products",$conn);
$get_iteminfo ="SELECT".$select."from products";
$result=mysql_query($get_iteminfo);
for $counter=0;
$row=mysql_fetch_row($result);
$counter++ {
print ("<tr>");
foreach ($row as $key=>$value)
print("<td>$value</td>");
}
</table>
<?php print ("$counter") ?> results.
</body>
</html>
This is the entire script for the most part. When my select
criteria is "*", I get a display of all of the results on a
row by row basis. The display also shows "not yet declared"
for columns where no item is placed yet.
I believe that my problem is with the call to the Mysql database.
I am hoping that the .$select. criteria will pick up the
appropriate selected choice from the form.
Hope this is clearer than my previous posting.
James
i.e. Skincare |Giftbag |Lipbalm
Honey & Blackseed |Giftbag
-
jamessirleaf
- Forum Newbie
- Posts: 8
- Joined: Tue Apr 13, 2004 7:24 am
- Location: Reading, UK
I still need some help to resolve this issue. Alternatively, I could run
a condition statement where I do as follows:
if $_POST[select] = "haircare"
mysql_query="select * from products where item_title="haircare";
elseif $_POST[select] ="skincare"
mysql_query ="select * from products where item_title="skincare";
else
"SELECT " .$select. "from products";
When run using these conditional statements however, I get only
values for item 1 i.e. Haircare. although the information and printed
values are absolutely correct.
Will Appreciate some input.
James
a condition statement where I do as follows:
if $_POST[select] = "haircare"
mysql_query="select * from products where item_title="haircare";
elseif $_POST[select] ="skincare"
mysql_query ="select * from products where item_title="skincare";
else
"SELECT " .$select. "from products";
When run using these conditional statements however, I get only
values for item 1 i.e. Haircare. although the information and printed
values are absolutely correct.
Will Appreciate some input.
James
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA
-
jamessirleaf
- Forum Newbie
- Posts: 8
- Joined: Tue Apr 13, 2004 7:24 am
- Location: Reading, UK
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA
-
jamessirleaf
- Forum Newbie
- Posts: 8
- Joined: Tue Apr 13, 2004 7:24 am
- Location: Reading, UK
-
magicrobotmonkey
- Forum Regular
- Posts: 888
- Joined: Sun Mar 21, 2004 1:09 pm
- Location: Cambridge, MA