Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
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  
Old July 21st, 2003, 05:12 PM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
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>

Reply With Quote
  #2  
Old July 21st, 2003, 06:04 PM
tkarkkainen's Avatar
tkarkkainen tkarkkainen is offline
Moderator
Click here for more information
 
Join Date: Apr 2007
Location: Finland
Posts: 2,320 tkarkkainen User rank is Lance Corporal (50 - 100 Reputation Level)tkarkkainen User rank is Lance Corporal (50 - 100 Reputation Level)tkarkkainen User rank is Lance Corporal (50 - 100 Reputation Level)  Folding Points: 10700 Folding Title: Novice Folder
Time spent in forums: 6 Days 8 h 46 m 16 sec
Reputation Power: 4
RE: NEW at PHP,need code help

What is the problem?

Reply With Quote
  #3  
Old July 22nd, 2003, 07:33 PM
superalloy superalloy is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Washington DC
Posts: 58 superalloy User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
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)

Reply With Quote
  #4  
Old July 22nd, 2003, 07:55 PM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 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.

Reply With Quote
  #5  
Old July 22nd, 2003, 08:06 PM
Ashkhan Ashkhan is offline
Contributing User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 372 Ashkhan User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 24 m 57 sec
Reputation Power: 2
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";

Reply With Quote
  #6  
Old July 22nd, 2003, 08:30 PM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
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!!!

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > NEW at PHP,need code help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway