|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stay one step ahead of the competition. Evaluate and give feedback
on some of the hottest web development tools on the market today.
Make your opinion heard! Click
Here
|
|
#1
|
|||
|
|||
|
NEW at PHP,need code help
Searching table for specific products that is entered in from another form!
<HTML> <?php if ($product) { $sql="SELECT * FROM PRODTABLE WHERE $searchtype LIKE '%$product%' ORDER BY prodname ASC"; $db = mysql_connect("localhost", "root", ""); mysql_select_db("shop",$db); $result = mysql_query($sql,$db); while ($myrow = mysql_fetch_array($result)) { echo $myrow["prodname"] } } else echo"product cannot be found"; { ?> </HTML> |
|
#2
|
||||
|
||||
|
RE: NEW at PHP,need code help
What is the problem?
|
|
#3
|
|||
|
|||
|
RE: NEW at PHP,need code help
if you echo $sql prior to the database connection do you see:
SELECT * FROM PRODTABLE WHERE ???? LIKE '%$product%' ORDER BY prodname ASC (i.e. $product isn't being replaced by $product) |
|
#4
|
|||
|
|||
|
RE: NEW at PHP,need code help
The variable value will not be used due to the fact that the variable is enclosed between single quotes. See the section on single quotes in Matts 'String Primer' tutorial for an explaination.
|
|
#5
|
|||
|
|||
|
RE: NEW at PHP,need code help
It should work because the whole statement is enclosed between double quotes and the single quotes are between them too.
You can try this: $sql="SELECT * FROM PRODTABLE WHERE $searchtype LIKE '%".$product."%' ORDER BY prodname ASC"; |
|
#6
|
|||
|
|||
|
RE: NEW at PHP,need code help
ashkhan is correct, it should replace the value I didn't pay close enough attention to how the query was constructed before commenting. tested it myself and it worked. my bad!!!
|
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > NEW at PHP,need code help |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|