php - Using variable data to replace hard-coded table name in a query -


let's have prepared statement, in case, 1 selects photo information specific table in database:

$conn = dbconnect('query'); $bgimage = "select photo_fname     photos_bn     gallery_id = ?     limit $curpage,".$totalpix; $stmt = $conn->prepare($bgimage); $stmt->bind_param('i', $gallery); $stmt->bind_result($pfname); $stmt->execute(); $stmt->store_result(); $stmt->fetch(); 

and since have several tables in database deal specific photo themes, 1 assume need separate queries each table. above code selects information table, photos_bn, have other tables, we'll call them, photos_bq , photos_ps.

this may insanely obvious question, how go replacing table name variable passed page via query string or session variable table name in query not hard coded, part of prepared statement?

many thanks!

you have:

$bgimage = "select photo_fname ".$_get["querystringvar"]." gallery_id = ? limit $curpage,".$totalpix;  

be warned leaves vulerable sql injection


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -