[GLLUG] Retrieving a row from mysql

Shawn Paige paig2956 at yahoo.com
Tue Feb 17 07:49:16 EST 2004


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


More information about the linux-user mailing list