Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: [PHP-DB] letting a table name be a constant
Ben Galin wrote:

> I want to define() TABLE as a constant instead of using the variable $tabl
e
>
> [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

Report this thread to moderator Post Follow-up to this message
Old Post
John Holmes
08-24-04 01:55 AM


Re: [PHP-DB] letting a table name be a constant
On Aug 23, 2004, at 8:12 PM, John Holmes wrote:

> You can't have a constant in a string. You'd do it like this:
>
> mysql_query("INSERT INTO " . TABLE . " (`id`,`name`) VALUES
> ('','$name')");

Thanks, John and Justin.  Wasn't thinking about that.

> 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.

You're right.  It doesn't run.  I retyped instead of copy-and-paste'd;
that's a typo.

Cheers,
Ben

Report this thread to moderator Post Follow-up to this message
Old Post
Ben Galin
08-24-04 01:55 AM


Re: [PHP-DB] letting a table name be a constant
On Tuesday 24 August 2004 08:18, Ben Galin wrote:

> You're right.  It doesn't run.  I retyped instead of copy-and-paste'd;
> that's a typo.

Please, when you post code make sure they're verbatim by using copy & paste.
That way people can focus on your actual problem rather than on your typos.

--
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
------------------------------------------
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-db
------------------------------------------
/*
The Marines:
The few, the proud, the dead on the beach.
*/

Report this thread to moderator Post Follow-up to this message
Old Post
Jason Wong
08-24-04 08:57 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PHP DB archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:46 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.