Jump to content

Only Shows 'Description' (Numbers?)


justlukeyou

Recommended Posts

I set up the following code to successfully individual items based on the id number. ?id=1 etc.  However, I thought it would be simple to change to show another row so I changed all the terms to 'description'.  However, if I enter ?description=abcde it shows nothing.  But if I type in ?description=description is bizarrely shows everything.

 

The only thing I can only put it down to is numbers.  Does $_GET react differently react differently to numbers or does it require commas surrounding the string?

 

 


<?php
if( isset($_GET['description']))
$_GET['description'];
$query = "SELECT * FROM productfeed WHERE description = $description LIMIT 0, 10";
$fetchdata = mysql_query($query) or die("query: $query<br>This has an error: " . mysql_error() . '<br>');
while($row = mysql_fetch_array($fetchdata)) {
$id = $row['id'];
$image = $row['awImage'];
$link = $row['link'];
$description = $row['description'];
$fulldescription = $row['fulldescription'];
$price = $row['price'];





echo "<div class='productdisplayshell'>
<div class='productdisplayoutline'>
<div class='productborder'><center>
<a href='$link' target='_blank'><img src='$image'/></a>
</center> </div></div>
<div class='productdescriptionoutline'>
<div class='productdescriptionbox'>
<a href='$link' target='_blank' >$description</a>
</div>
<div class='productfulldescriptionbox'>$fulldescription</div>
</div>
<div class='productpriceoutline'>
<div class='productpricebox'>
<center>&#163; $price</center>
</div>
<div class='productbuybutton'>
<center><a href='$link' target='_blank' ><img src=/images/buybutton.png /></a></center>
</div>
</div>
</div>";
} 
?>

Link to comment
Share on other sites

Thanks,

 

I have tried the following but it just brings up an error regardless of what I search.  I have not tried to define it anywhere.

 

<?php
$query = "SELECT * FROM productfeed WHERE $description =  LIMIT 0, 10";
$fetchdata = mysql_query($query) or die("query: $query<br>This has an error: " . mysql_error() . '<br>');
while($row = mysql_fetch_array($fetchdata)) {
$id = $row['id'];
$image = $row['awImage'];
$link = $row['link'];
$description = $row['description'];
$fulldescription = $row['fulldescription'];
$price = $row['price'];





echo "<div class='productdisplayshell'>
<div class='productdisplayoutline'>
<div class='productborder'><center>
<a href='$link' target='_blank'><img src='$image'/></a>
</center> </div></div>
<div class='productdescriptionoutline'>
<div class='productdescriptionbox'>
<a href='$link' target='_blank' >$description</a>
</div>
<div class='productfulldescriptionbox'>$fulldescription</div>
</div>
<div class='productpriceoutline'>
<div class='productpricebox'>
<center>&#163; $price</center>
</div>
<div class='productbuybutton'>
<center><a href='$link' target='_blank' ><img src=/images/buybutton.png /></a></center>
</div>
</div>
</div>";
} 
?>

Link to comment
Share on other sites

Thanks,

 

I tried that but it still keeps up with the same message.

 

When I was using the idea number it was working fine but when I try to use the same principal on other strings it doesn't work. 

 

Previously I had this

 

$query = "SELECT * FROM productfeed WHERE id = $id";

    --------> id1

 

$query = "SELECT * FROM productfeed WHERE description = $description

  --------> I dont want the first description to be in place but everything I try just comes back with the message

 

query: SELECT * FROM productfeed WHERE description = description LIMIT 0, 10

 

 

Link to comment
Share on other sites

Thanks,

 

I now have the following code.  When I use this as my link:

 

phpdescriptionresults.php?description=Description

 

it displays everything in my database. But if I try:

 

phpdescriptionresults.php?description=Descriptionproduct

 

It comes up with the following error:

 

query: SELECT * FROM productfeed WHERE description = Descriptionproduct

This has an error: Unknown column 'Descriptionproduct' in 'where clause'

 

I am setting the only output to description?

 

<?php
if (isset($_GET['description']))
$query = "SELECT * FROM productfeed WHERE description = $description";
$fetchdata = mysql_query($query) or die("query: $query<br>This has an error: " . mysql_error() . '<br>');
while($row = mysql_fetch_array($fetchdata)) {
$id = $row['id'];
$image = $row['awImage'];
$link = $row['link'];
$description = $row['description'];
$fulldescription = $row['fulldescription'];
$price = $row['price'];

Link to comment
Share on other sites

This is what Pika means...

change this:

<?php
if( isset($_GET['description']))
$_GET['description'];
$query = "SELECT * FROM productfeed WHERE description = $description LIMIT 0, 10";
$fetchdata = mysql_query($query) or die("query: $query<br>This has an error: " . mysql_error() . '<br>');
while($row = mysql_fetch_array($fetchdata)) {
$id = $row['id'];
$image = $row['awImage'];
$link = $row['link'];
$description = $row['description'];
$fulldescription = $row['fulldescription'];
$price = $row['price'];

 

to this:

<?php
if( isset($_GET['description']))
$description = $_GET['description'];
$query = "SELECT * FROM productfeed WHERE description = $description LIMIT 0, 10";
$fetchdata = mysql_query($query) or die("query: $query<br>This has an error: " . mysql_error() . '<br>');
while($row = mysql_fetch_array($fetchdata)) {
$id = $row['id'];
$image = $row['awImage'];
$link = $row['link'];
/* redundent line removed here */
$fulldescription = $row['fulldescription'];
$price = $row['price'];

Link to comment
Share on other sites

Hi,

 

If I use the following code it displays everything in the database and changes the description of each $description to "description". 

 

if( isset($_GET['description']))
$description = $_GET['description'];
$query = "SELECT * FROM productfeed WHERE description = $description LIMIT 0, 10";
$fetchdata = mysql_query($query) or die("query: $query<br>This has an error: " . mysql_error() . '<br>');
while($row = mysql_fetch_array($fetchdata)) {
$id = $row['id'];
$image = $row['awImage'];
$link = $row['link'];
/* redundent line removed here */
$fulldescription = $row['fulldescription'];
$price = $row['price'];

 

However,

 

if just add the following single commas likes this I get a blank screen so I'm quite puzzled as to whats doing.  Ive tried around 20 variations but this seems to be the closest I can get it.

 

$query = "SELECT * FROM productfeed WHERE description = '$description' LIMIT 0, 10";

 

Link to comment
Share on other sites

Actually, if I remove

 

/* redundent line removed here */

 

and enter back in the following it no longer replaces each description with "description" but now shows the correct description. 

 

$description = $row['description'];

 

However, it now shows every product in database when I use "phpdescriptionresults2.php?description=description" in the search bar but if use "phpdescriptionresults2.php?description=redwidget" it comes with the following error:

 

query: SELECT * FROM productfeed WHERE productname = redwidget LIMIT 0, 10

This has an error: Unknown column 'productname' in 'where clause'

 

So I am back to where I was earlier.  At least I think I am!

Link to comment
Share on other sites

Hi,

 

Excluding the full domain name this (/test/phpdescriptionresults2.php?description=description) shows every items.  This (/test/phpdescriptionresults2.php?description=redwidget) shows the following error:

 

query: SELECT * FROM productfeed WHERE description = redwidget LIMIT 0, 10

This has an error: Unknown column 'redwidget' in 'where clause'.  I just cant see why only the "description" works instead of the actual product name.  Is it because I am using "description" twice.  In the echo and as a query?

 

This is the full code I have currently:

 

<?php
if( isset($_GET['description']))
$description = $_GET['description'];
$query = "SELECT * FROM productfeed WHERE description = $description LIMIT 0, 10";
$fetchdata = mysql_query($query) or die("query: $query<br>This has an error: " . mysql_error() . '<br>');
while($row = mysql_fetch_array($fetchdata)) {
$id = $row['id'];
$image = $row['awImage'];
$link = $row['link'];
$description = $row['description'];
$fulldescription = $row['fulldescription'];
$price = $row['price'];






echo "<div class='productdisplayshell'>
<div class='productdisplayoutline'>
<div class='productborder'><center>
<a href='$link' target='_blank'><img src='$image'/></a>
</center> </div></div>
<div class='productdescriptionoutline'>
<div class='productdescriptionbox'>
<a href='$link' target='_blank' >$description</a>
</div>
<div class='productfulldescriptionbox'>$fulldescription</div>
</div>
<div class='productpriceoutline'>
<div class='productpricebox'>
<center>&#38;#163; $price</center>
</div>
<div class='productbuybutton'>
<center><a href='$link' target='_blank' ><img src=/images/buybutton.png /></a></center>
</div>
</div>
</div>";
} 
?> 

Link to comment
Share on other sites

Let's start with this: description=description is no different than writing 1=1. It will always be true, and therefore will match every record in the database. In the query string, $description needs to be in quotes: WHERE description = '$description'. But, since your form is somehow sending the string literal 'description', it probably won't match any records at all, unless the value in the record's description field is actually 'description'.

Link to comment
Share on other sites

Hi,

 

The title of field is 'description' as this is the one I am echoing so I know it works.

 

I did try the following but it didn't do anything.  Is there anything else I can do to improve the situation?

 

if( isset($_GET['productname']))
$description = $_GET['productname'];
$query = "SELECT * FROM productfeed WHERE productname = $description LIMIT 0, 10";$fetchdata = mysql_query($query) or die("query: $query<br>This has an error: " . mysql_error() . '<br>');

Link to comment
Share on other sites

Hi,

 

Many thanks, I am trying to aichieve this:

 

"phpdescriptionresults2.php?description=red-widget"  --- For this to display every 'red widget' in my database.

 

Following is all the code I have:

 

<?php
if( isset($_GET['description']))
$description = $_GET['description'];
$query = "SELECT * FROM productfeed WHERE description = $description LIMIT 0, 10";
$fetchdata = mysql_query($query) or die("query: $query<br>This has an error: " . mysql_error() . '<br>');
while($row = mysql_fetch_array($fetchdata)) {
$id = $row['id'];
$image = $row['awImage'];
$link = $row['link'];
$description = $row['description'];
$fulldescription = $row['fulldescription'];
$price = $row['price'];



echo "<div class='productdisplayshell'>
<div class='productdisplayoutline'>
<div class='productborder'><center>
<a href='$link' target='_blank'><img src='$image'/></a>
</center> </div></div>
<div class='productdescriptionoutline'>
<div class='productdescriptionbox'>
<a href='$link' target='_blank' >$description</a>
</div>
<div class='productfulldescriptionbox'>$fulldescription</div>
</div>
<div class='productpriceoutline'>
<div class='productpricebox'>
<center>&#38;#163; $price</center>
</div>
<div class='productbuybutton'>
<center><a href='$link' target='_blank' ><img src=/images/buybutton.png /></a></center>
</div>
</div>
</div>";
} 
?> 

Link to comment
Share on other sites

As others have said, strings MUST be quoted in the  query. Change:

<?php
$query = "SELECT * FROM productfeed WHERE description = $description LIMIT 0, 10";
?>

to

<?php
$query = "SELECT * FROM productfeed WHERE description = '$description' LIMIT 0, 10";
?>

 

Ken

Link to comment
Share on other sites

If I put the following -----here curlys in does something very wierd.  It only shows the description I am searching and cuts out everything else such as the image.

 

Is it possible to get a code which overrights what is in the string because that is what I appear to be doing.

 

<?php
if( isset($_GET['description']))
$description = $_GET['description'];
$query = "SELECT * FROM productfeed WHERE description = '$description' LIMIT 0, 10";
$fetchdata = mysql_query($query) or die("query: $query<br>This has an error: " . mysql_error() . '<br>');
while($row = mysql_fetch_array($fetchdata)) {
$id = $row['id'];
$image = $row['awImage'];
$link = $row['link'];
$description = $row['description'];
$fulldescription = $row['fulldescription'];
$price = $row['price'];
} -----here




{ -----here
echo "<div class='productdisplayshell'>
<div class='productdisplayoutline'>
<div class='productborder'><center>
<a href='$link' target='_blank'><img src='$image'/></a>
</center> </div></div>
<div class='productdescriptionoutline'>
<div class='productdescriptionbox'>
<a href='$link' target='_blank' >$description</a>
</div>
<div class='productfulldescriptionbox'>$fulldescription</div>
</div>
<div class='productpriceoutline'>
<div class='productpricebox'>
<center>&#38;#163; $price</center>
</div>
<div class='productbuybutton'>
<center><a href='$link' target='_blank' ><img src=/images/buybutton.png /></a></center>
</div>
</div>
</div>";
} 
?> 

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.