Jump to content


Photo

select from where - question


  • Please log in to reply
5 replies to this topic

#1 aprentis2

aprentis2
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 17 May 2006 - 12:44 AM

I have a question about a query, I am using the query to select lines from a database that would match po_number is the table. The problem is when I enter a po_number it may or may not include the character " - ".

When I do not include the character just numbers & letters (123abs456) it returns the query with no problems, But when I use (123-abc-456) it gives me an error.

rows, [] , error: Unknown column 456 in 'where clause'

any help would be appreciated.


<?

$orderid=$_GET['id'];
$sql="select * from sc_order where po_number=$orderid";
mysql_select_db($dbname,$db);
$result=mysql_query($sql);
$dt=date('Y-m-d')." / ".date('h:i:s');

if(! $result || mysql_error() || mysql_num_rows($result) < 1)
{
echo sprintf('%s rows, [%s] , error: %s',
@mysql_num_rows($result),
$query,
mysql_error());
exit;
}
else
{
echo"No errors found";
}
?>

<table align="center" border="0" class="tablegreenl" width="70%">

<tr class="tablegreend">
<td><b>Date/Time</b></td>
<td align="right"><b>User Name</b></td>
<td align="right"><b>Database</b></td>
<td align="right"><b>Product Id</b></td>
<td align="right"><b>Quantity</b></td>

<?
if(mysql_num_rows($result)<1)
{
?>
<tr><td align="center" colspan="5">No Records</td></tr>
<?
}
?>
<tr><td align="center" colspan="5"><hr></td></tr>
<tr>
<?
while($rs=mysql_fetch_array($result))
{
?>

<td><?=$dt?></td>

<td align="center"><?=getname('sc_user','userid',$rs['userid'],'username')?></td>
<td align="center"><?=$dbname?></td>
<td align="center"><?=getname('sc_products','prod_id',$rs['prod_id'],'prod_name')?></td>
<td align="center"><?=$rs['quantity']?></td>

<tr>
<?
}
?>



#2 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 17 May 2006 - 01:10 AM

try putting some quotes around it:

$sql="select * from sc_order where po_number=[!--coloro:red--][span style=\"color:red\"][!--/coloro--]'[!--colorc--][/span][!--/colorc--]$orderid[!--coloro:red--][span style=\"color:red\"][!--/coloro--]'[!--colorc--][/span][!--/colorc--]";
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#3 aprentis2

aprentis2
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 17 May 2006 - 01:12 AM

I tried quotes, I then get the error

rows, [] , error: Unknown column '123-abc-456' in 'where clause'

works fine if I remove the "-" 's from the po_number

#4 .josh

.josh
  • Staff Alumni
  • .josh
  • 14,871 posts

Posted 17 May 2006 - 01:19 AM

umm... so are you doing something to $orderid before you use it in the query, like stripslahes or striptags or something?

edit : nvm you aren't.. hmm...
Did I help you? Feeling generous? Buy me lunch! 
Please, take the time and do some research and find out how much it would have cost you to get your help from a decent paid-for source. A "roll-of-the-dice" freelancer will charge you $5-$15/hr. A decent entry level freelancer will charge you around $15-30/hr. A professional will charge you anywhere from $50-$100/hr. An agency will charge anywhere from $100-$250/hr. Think about all this when soliciting for help here. Think about how much money you are making from the work you are asking for help on. No, we do not expect you to pay for the help given here, but donating a few bucks is a fraction of the cost of what you would have paid, shows your appreciation, helps motivate people to keep offering help without the pricetag, and helps make this a higher quality free-help community :)

#5 aprentis2

aprentis2
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 17 May 2006 - 01:23 AM

The orderid is actually the po_number tranferred via url link.

I left the top few lines of the code out in the above because I didnt think they had anything to do with the actual problem.

I can echo $po_number and echo $orderid and they are the same.

I'm sure it has something to do with the dashes, Not sure this is really the first php project I have really worked on. So far everything has been great until this problem.

#6 aprentis2

aprentis2
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 17 May 2006 - 01:57 AM

I tried the quotes again, Seems to be working now.

I'm thinking I may have mistyped the quotes before maybe using ` or " not sure.

Thank you very much for the help




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users