letting a table name be a constant
| From: | Ben Galin | Date: | Tue, 24 Aug 2004 00:06:40 +0000 |
| Subject: | letting a table name be a constant | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-35859@lists.php.net to get a copy of this message | ||
Hello,
Regarding this code:
[PHP code]
// This works
$name="name";
$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]
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]
Changing the query line to
$mysql_query("INSERT INTO TABLE (id,name) VALUES ('','$name')");
or
$mysql_query("INSERT INTO 'TABLE' (id,name) VALUES ('','$name')");
has no effect.
I also tried to
define("TABLE", "mytable");
which, too, didn't work.
Would appreciate any advice,
Ben