Jump to content

Search only works with Table column name


rgrady3

Recommended Posts

I have tried several different codes to create a database search of a table that includes column name "Product," "Price" and "InStock."  I am trying to search the "Product column and in each code when I enter a term I know to be in the table it comes up with an error (usually "Unknown Column 'input' in 'where' or

mysql_fetch_array(): supplied argument is not a valid MySQL result resource in").

 

The only way the search works is if I enter the actual name of the Column (in this case "Product") and it displays the entire table.

 

Please help....

Link to comment
Share on other sites

The old code with the original problem looked like this:

 

$Link = mysql_connect($Host, $User, $Password);

$Query="SELECT * from $TableName WHERE Product = $productid";

$Result= mysql_db_query ($DBName, $Query, $Link);

 

Here is the new code per the suggestion:

 

$Link = mysql_connect($Host, $User, $Password);

$Query="SELECT Product, Price, InStock from $TableName WHERE Product = '$productid'";

$Result= mysql_db_query ($DBName, $Query, $Link);

 

Now I get a blank page when I search for anything but "Product."  When I search "Product" I get the following output:

 

Product:Product, Price: Price In Stock: InSto

 

Print Code is as follows:

 

while ($Row = mysql_fetch_array ($Result))

{

print (" Product:$Row[Product], Price: $Row[Price] In Stock: $Row[inStock]<BR> ");

}

Link to comment
Share on other sites

CORRECTION: I now get no output or error except the echoed input from the search form.  Here is the entire code:

 

<?php

 

echo "$productid";

 

$Host="localhost";

$User="xxxx";

$Password="xxxx";

$DBName="xxxx";

$TableName="xxxxxx";

 

$Link = mysql_connect($Host, $User, $Password);

$Query= "SELECT Product, Price, InStock from $TableName WHERE Product = '$productid'";

$Result= mysql_db_query ($DBName, $Query, $Link);

 

while ($Row = mysql_fetch_array ($Result))

 

{

print (" Product: $Row[Product], Price: $Row[Price] In Stock: $Row[inStock]<BR> ");

}

mysql_close ($Link);

Link to comment
Share on other sites

Still get the same result.  To make sure things were working I changed "Product" in my $Query line to include a typo and got back an error "Unknown column 'Produc' in 'where clause' so at least that part is working.  Should I attempt a different print method?

Link to comment
Share on other sites

I tried it without the where clause and it printed the entire table.

 

What I do not understand is I echo $productid as the first command and it displays every time including this time when I inputted the search value but did not have the WHERE clause in my SELECT line.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.