Link to home
Start Free TrialLog in
Avatar of MrTV
MrTVFlag for Thailand

asked on

put variable in sql statement php

This code is work if I change $table to  gel in line 12     how can I change $table to correct way

[list=1]


$table = "gel";

echo "$table";

$sql ='INSERT INTO pong8_maintable ("timestamp8","Last","TradePrice", "TradeVolume" , "BestBid") 
SELECT 
cast(public.gel."Timestamp" as timestamp) ,

cast(public.$table. "Last" as numeric)  ,

cast(public.gel."Trade Price" as numeric)  ,  
[/list]

Open in new window




Error
pg_query(): Query failed: ERROR: syntax error at or near "$" LINE 8: cast(public.$table. "Last" as numeric) , ^
Error
Error while accessing the database:
ERROR: syntax error at or near "$" LINE 8: cast(public.$table. "Last" as numeric) ,
SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
ASKER CERTIFIED SOLUTION
Avatar of skullnobrains
skullnobrains

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of MrTV

ASKER

Thank you