[GLLUG] Retrieving a row from mysql

Szymon Machajewski SMachaje at grcc.edu
Tue Feb 17 08:26:24 EST 2004


As a good practice you could always use another string variable to
contain your sql:
 
$query = ("SELECT * FROM " . $tablename . "
WHERE name= '" . $name . "' AND accountnum= " .
$accnum);"

and then: myql_query($query);
 
This way you could put: echo $query;
 
for degugging.
 
 
Sincerely,
 
Szymon Machajewski MCSD, CNA, MySQL Core
Grand Rapids Community College
 
Open Sourceror


>>> Shawn Paige <paig2956 at yahoo.com> 2/17/2004 7:49:16 AM >>>

Hi Seth-

The values for your variable names will not be
inserted when you run the command below.  The actual
SQL that will be sent to MySQL will be:

SELECT * FROM $tablename WHERE name= '$name' AND
accountnum= $accnum

Try changing your line of code to the following ("."
is used for string concatenation):

query = mysql_query("SELECT * FROM " . $tablename . "
WHERE name= '" . $name . "' AND accountnum= " .
$accnum);"

Think I got it right.  The other good idea that was
mentioned in the thread is to print out the SQL
statement you are trying to run, and then trying to
run it directly against MySQL to check for errors.

Hope this helps.
Shawn

--- Seth Bembeneck <sbdataspiller at sbcglobal.net>
wrote:
> I'm working on my database project (See 'MySql:
> Database inside of a
> Database').
>  
> It was suggested that I have an account number in
> each table.
>  
> So now for example my table is
> (The real table has a lot more info, but hopefully
> this demonstrates
> what I'm trying to do)
>  
> Table name: players
> name - accountnum - blah -blah
> Seth   -- 12              -- y      - n
> You   --- 34             --- y     -k
> Blah - N                -- more -- no
>  
> I have a query like this in php:
>  
> $name = 'Seth';
> $accnum= 12;
> $tablename = 'players'
> query = mysql_query("SELECT * FROM $tablename WHERE
> name= '$name' AND
> accountnum= $accnum");
>  
>  
> When I run this, I get a message saying that I have
> an error in my
> syntext and to check the manuel for my version of
> MySql for the right
> syntext to use near " at line 1.
>  
> Why?
>  
> I specified accountnum in the table creation script
> as
>  
> accountnum int(10) unsigned NOT NULL
>  
> Thanks,
>  
> Seth
> > _______________________________________________
> linux-user mailing list
> linux-user at egr.msu.edu
> http://www.egr.msu.edu/mailman/listinfo/linux-user
> 


__________________________________
Do you Yahoo!?
Yahoo! Finance: Get your refund fast by filing online.
http://taxes.yahoo.com/filing.html
_______________________________________________
linux-user mailing list
linux-user at egr.msu.edu
http://www.egr.msu.edu/mailman/listinfo/linux-user

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.egr.msu.edu/mailman-archives/linux-user/attachments/20040217/48f8997f/attachment.htm


More information about the linux-user mailing list