Using PHP variables inside SQL statements?

Posted by Homer on Stack Overflow See other posts from Stack Overflow or by Homer
Published on 2010-04-01T02:19:28Z Indexed on 2010/04/01 2:23 UTC
Read the original article Hit count: 323

Filed under:
|

For some reason I can't pass a var inside a mysql statement. I have a function that can be used for multiple tables. So instead of repeating the code I want to change the table that is selected from like so,

function show_all_records($table_name) {

     mysql_query("SELECT * FROM $table_name");

etc, etc...

}

And to call the function I use show_all_records("some_table") or show_all_records("some_other_table")

depending on which table I want to select from at the moment. But it's not working, is this because variables can't be passed through mysql statements?

© Stack Overflow or respective owner

Related posts about php

Related posts about mysql