Re: letting a table name be a constant

From: Date: Tue, 24 Aug 2004 03:12:44 +0000
Subject: Re: letting a table name be a constant
References: 1  Groups: php.db 
Request: Send a blank email to php-db+get-35861@lists.php.net to get a copy of this message
Ben Galin wrote:
I want to define() TABLE as a constant instead of using the variable $table [PHP code] // This runs without an error but does *not* insert a new row $name="name"; define("TABLE", "mytable"); $mysql_connect("localhost","","") or die("Error: ".mysql_error()); $mysql_select_db("mydb") or die("Error: ".mysql_error()); $mysql_query("INSERT INTO TABLE (id,name) VALUES ('','$name')"); [/PHP code]
You can't have a constant in a string. You'd do it like this: mysql_query("INSERT INTO " . TABLE . " (id,name) VALUES ('','$name')"); The other error you have, and I don't know how you think this code runs, are the dollar signs before mysql_connect(), mysql_select_db() and mysql_query() are not needed. -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals – www.phparch.com

« previous php.db (#35861) next »