There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Software Development
Tag Cloud
audio blue screen boot bsod computer cpu crash dell desktop driver drivers error excel external hard drive firefox format freezes freezing hard drive hardware hijackthis install internet internet explorer itunes keyboard laptop malware motherboard mouse network networking outlook 2007 power printer problem ram router screen slow sound trojan usb virus vista vista 32-bit windows windows xp winxp wireless
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Software & Hardware > Software Development >
Help using a variable in MySql SELECT statement


Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members. Enjoy!

Closed Thread
 
Thread Tools
HowdeeDoodee's Avatar
Senior Member with 218 posts.
 
Join Date: Aug 2004
Experience: Intermediate
16-Oct-2004, 01:10 PM #1
Help using a variable in MySql SELECT statement
I want to use a variable at the end of a MySql statement but cannot get the following SELECT statement to work using a variable. I can get the SELECT statement to work if I use a text string in the statement.

The following 2 statements return an error from the mysql_query

$input = 'test';
$query = ("SELECT * FROM `View1` WHERE `Topic` = $input");

$query = ("SELECT * FROM `View1` WHERE `Topic` = '$input'");


The following statement does NOT return an error from the mysql_query

$query = "SELECT * FROM `View1` WHERE 'Topic` = 'test'";


$result = mysql_query($query) or die("ERROR63");
[/size][/size]

Help would be appreciated.
Chicon's Avatar
Computer Specs
Distinguished Member with 6,695 posts.
 
Join Date: Jul 2004
Location: 50° 34' 07.13" N - 04° 10' 23.
Experience: Second socks retriever
16-Oct-2004, 07:59 PM #2
Hi HowdeeDoodee;

Did you try this ?
$query = "SELECT * FROM `View1` WHERE `Topic` = " + $input;
HowdeeDoodee's Avatar
Senior Member with 218 posts.
 
Join Date: Aug 2004
Experience: Intermediate
17-Oct-2004, 02:14 PM #3
Chicon...

No, sorry that did not work. However, I did resolve the issue.

$input must be made to appear as if the string or word "test" is enclosed by single quotes when the SELECT statement is evaluated or run.

Here is the fix.

$input = "'test'";

the word "test" is enclosed first with single quotes and then in double quotes. By using double quotes the single quotes appear to be part of the string expression.
Closed Thread

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.



Thread Tools


You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 11:08 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.