Problem with SELECT

Hi,

I have a page with a link

<a href="Contributor.php?action=&SubCat=<?php echo $row["writer"];
?>"><?php echo $row["writer"];?></a>

that does to a page with a SELECT

$query = "SELECT * FROM news WHERE writer='$SubCat' ";

But it is not pulling any data from the database. If I do this
$query = "SELECT * FROM news WHERE writer='Bob Smith' ";
works great??

also
the ULR reads -
Contributor.php?action=&SubCat=Bob%20Smith
so I know the link is correct ....

but for the life of me I can't figure out whats wrong with the SELECT
statement?

If anyone can help me with this I would be forever in your Debt.

Thanks

here is the complete Contributor.php script.


<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"><!--
#BeginTemplate "/Templates/journ.dwt" -->
<head>
<meta http-equiv="content-type" content="text/html;
charset=ISO-8859-1" />
<!-- #BeginEditable "doctitle" -->
<title>paper</title>
<!-- #EndEditable -->
<link rel="stylesheet" href="Styles/template.css" type="text/css" />
</head>
<body>

<div id="container">
<div id="logo"><img src="Images/logo.jpg" border="0"
alt="logo"></div>
<div id=bar><form action="a.php" method="POST">
<label for="searchtxt">Search our archives:</label>
<input id="searchtxt" type="text" name="searchtxt" value="" />
<input class="button" type="submit" value="Search" /></form>
</div>
<div id="header">
<!-- #BeginEditable "Adds" --><div id="athlete"><img
src="../Images/Athlete.gif" border="0" alt="AthleteMonth">
<img src="../Images/AthleteMonth.jpg" border="0"
alt="AthleteMonth"><br>
Susan smith</div>
<br>
<? include("Ads.php") ?><!-- #EndEditable -->
</div>
<div id="sidebar">

<div id=writer>Your News</div>
<div id="navcontainer">

<ul id="navlist">
<table>
<?
$query = "SELECT DISTINCT cat FROM news";
$result = mysql_query($query)
or die ("no can do.");
while($row = mysql_fetch_array($result))
{
?>
<tr>
<td>
<li><a href="../<?php echo $row["cat"];?>"><?php echo
$row["cat"];?></a></li>
</td>
</tr>
<?php
}
?>
</table>
------------------------
<li>Classified Ads</li>
<li>Advertise With Us</li>
<li>About Us</li>
<li>Contact Us</li>
</ul>
</div>
<div id=writer>Visit our Sponsor</div>
<!-- #BeginEditable "Left" -->{Left}<!-- #EndEditable -->
</div>
<!-- #BeginEditable "middle" -->
<!--
-----------------------------------------NEWS--------------- ----------------------------------------------
-->
<div id="content">
<div id="bodymenu">News</div>
<table>
<?
$query = "SELECT * FROM news WHERE writer='$SubCat' ";
$result = mysql_query($query)
or die ("no can do.");
while($row = mysql_fetch_array($result))
{
?>
<tr>
<td>
<div id="bodyhead"><?php echo $row["heading"];?></div>
</td>
<td>
Issue: <?php echo $row["date"];?>
</td>
</tr>
<tr>
</tr>
<tr>
<td colspan=2>
<div id=bodywords>
<?php
$abc = ($row["article"]);
$abc=substr($abc,0,400);
echo $abc;
?>
......<span class="class1">Read the article</span>
</div>
</td>
</tr>
<?php
}
?>
</table>
</div>
<!-- #EndEditable --> </div>


</body>
<!-- #EndTemplate --></html>
bokke [ Do, 26 Oktober 2006 17:19 ] [ ID #1514649 ]

Re: Problem with SELECT

bokke schrieb:
> Hi,
>
> I have a page with a link
>
> <a href="Contributor.php?action=&SubCat=<?php echo $row["writer"];
> ?>"><?php echo $row["writer"];?></a>
>
> that does to a page with a SELECT
>
> $query = "SELECT * FROM news WHERE writer='$SubCat' ";

You are sure register_globals is on? Anyway it is recommended to use
$_GET['SubCat'].

> But it is not pulling any data from the database. If I do this
> $query = "SELECT * FROM news WHERE writer='Bob Smith' ";
> works great??
>
> also
> the ULR reads -
> Contributor.php?action=&SubCat=Bob%20Smith

So you have one record with 'Bob Smith' and another one with 'Bob%20Smith'?

Some recommendations:
- use urlencode() and urldecode() if you send GET data that could
contain any characters beyond a-z, A-Z and 0-9
- always pre-process transmitted data before putting them into the
database; also google for "SQL injectin" and "E-mail injection"
- regarding your HTML, use validator.w3.org to check it, and don't use a
strict XHTML doctype if you don't write strict XHTML.
- regarding posting, your message appears as a reply to an old thread in
my newsreader - was that your intention?

--
Markus
Markus Ernst [ Do, 26 Oktober 2006 18:07 ] [ ID #1514650 ]

Re: Problem with SELECT

Markus Ernst wrote:
> bokke schrieb:
> > Hi,
> >
> > I have a page with a link
> >
> > <a href="Contributor.php?action=&SubCat=<?php echo $row["writer"];
> > ?>"><?php echo $row["writer"];?></a>
> >
> > that does to a page with a SELECT
> >
> > $query = "SELECT * FROM news WHERE writer='$SubCat' ";
>
> You are sure register_globals is on? Anyway it is recommended to use
> $_GET['SubCat'].
>
> > But it is not pulling any data from the database. If I do this
> > $query = "SELECT * FROM news WHERE writer='Bob Smith' ";
> > works great??
> >
> > also
> > the ULR reads -
> > Contributor.php?action=&SubCat=Bob%20Smith
>
> So you have one record with 'Bob Smith' and another one with 'Bob%20Smith'?
>
> Some recommendations:
> - use urlencode() and urldecode() if you send GET data that could
> contain any characters beyond a-z, A-Z and 0-9
> - always pre-process transmitted data before putting them into the
> database; also google for "SQL injectin" and "E-mail injection"
> - regarding your HTML, use validator.w3.org to check it, and don't use a
> strict XHTML doctype if you don't write strict XHTML.
> - regarding posting, your message appears as a reply to an old thread in
> my newsreader - was that your intention?
>
> --
> Markus

Sorry - that was not my intention ...
as to your question - I only have a 'Bob Smith' but when the PHP looks
for it - it places %20 instead of the spaces i believe.

as to your other points - i'm looking them us as we speak.

thanks
bokke [ Do, 26 Oktober 2006 18:17 ] [ ID #1514651 ]
PHP » alt.php.sql » Problem with SELECT

Vorheriges Thema: $t variable in a query
Nächstes Thema: Unable to run mysql on win98se