User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 391,616 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,679 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser:

SQL problem - table names as variables

Join Date: May 2006
Posts: 8
Reputation: clarkeyboy is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
clarkeyboy clarkeyboy is offline Offline
Newbie Poster

Help SQL problem - table names as variables

  #1  
May 19th, 2006
Hi,

I have a slight problem. I am trying to create a mail service for a new game which I have started creating recently. Each user that registers also creates a table for their mail. As the usernames are variable and the table name is the username, I need to insert messages, subjects and "froms" into this variable table.

I am using the following code:

$to = $_SESSION["to"];
$subject = $_SESSION["subject"];
$message = $_SESSION["message"];
$from = $_SESSION["username"];
echo "To: $to<br>";
echo "Subject: $subject<br>";
echo "Message: $message<br>";
echo "From: $from<br>";
include 'connection.php';
if ($to <> "") {
	if ($subject <> "") {
		if ($message <> "") {
			$rsusers = $conn->Execute("INSERT INTO $to (subject, message, from) VALUES('$subject', '$message', '$from')");
		}
	}
}

The problem is that it will not accept $to as the table name - it just comes up with some nasty error about the syntax of my insert statement. Can anyone help me on this, please?
AddThis Social Bookmark Button
Reply With Quote  
All times are GMT -4. The time now is 12:26 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC