Using a variable as table name in insert script

Hey i have been trying for hours to get this script to work. It comes through fine if i don’t use a variable as the table name but i have different company’s using the same page and their information needs to post to different tables.

$info['table'] is the table name for each company specific to them in my users table.

<?php
$new = mssql_query("SELECT * FROM users WHERE webcode = ‘$webcode’")or die (mssql_error());
while($info = mssql_fetch_array( $new ))
{
$table = $info['table'];
}
if (isset($_POST['submit']))
{
$insert = "INSERT INTO $table (first_name, last_name, company)
VALUES (‘$fname’, ‘$lname’, ‘$company’)";

$add_member = mssql_query($insert);
if ($add_member)
{
header ("Location: registered.php");
?>
any thoughts? The problem im having is with the $table variable in the insert command, if i put an actual table name in that spot in place of the variable it runs perfectly.

Thanks in advance

View full post on Tycoon Talk

, , , , ,

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Get Adobe Flash playerPlugin by wpburn.com wordpress themes


RSS Site FeedRSS Site Feed

© 1992-2011 DC2NET™, Inc. All Rights Reserved