Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Inserting table name from scalar in sql prepare? 1

Status
Not open for further replies.

jollekox

Programmer
Feb 3, 2004
23
NO
Hi!

I am currently trying to insert a table name from an scalar into an sql prepare, is this possible in some way? (I am trying to make a multi-user blogging system)

The code I am trying to use looks like this:
$sth = $dbh->prepare('update ? set header = ? where id = ?');
$execute_result = $sth->execute($table, $header, $id);

And the scalar $table contains the table name :)

This does not work, the server only reports an error in the sql syntax.

Does anybody know a way to work around this? Or some other way to do the same thing?

Thanks in advance, and pardon my bad english!
Best regards,
Jo Andreas
 
I'm not certain that you can do that, but you can easily get the results you're looking for like:

[tt]sth = $dbh->prepare("update $table set header = ? where id = ?");
$execute_result = $sth->execute($header, $id);[/tt]

At least if you're certain that [tt]$table[/tt] is clean (not user-entered.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top