Jump to content

select from where - question


aprentis2

Recommended Posts

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.


[code]
<?

$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>
<?
}
?>

[/code]
Link to comment
Share on other sites

try putting some quotes around it:

$sql="select * from sc_order where po_number=[!--coloro:red--][span style=\"color:red\"][!--/coloro--][b]'[!--colorc--][/span][!--/colorc--][/b]$orderid[!--coloro:red--][span style=\"color:red\"][!--/coloro--][b]'[!--colorc--][/span][!--/colorc--][/b]";
Link to comment
Share on other sites

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.
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.