write to db
Posted by bschultz (bschultz), 24 June 2003Is it possible to have a write to db script that has a variable in it for the db name?
Here's what I'm using:
It says there's an error on line one...which confuses my little brain. Line 1 is the <?php...
Posted by admin (Graham Ellis), 24 June 2003Firstly, nothing to stop you using a variable name to select your database.
Now - the code error. I suspect that you might have some control character(s) in your file. This sometimes happens when files are transferred in ASCII when they should be transferred in binary (or vice versa), and on certain editiors to can mis-key and insert control codes in your source.
Solution ... call up the file in an editor that will display control codes and fix any problems revealed OR delete and retype the offending line.
Posted by bschultz (bschultz), 24 June 2003this file is a local file...it's never been ftp'ed. I use a program called phpcoder to code php, and it shows variables in red...the variable for the table name is still showing up in green (regular text). I can't find any way to display control codes...can you suggest an editor that does?
Posted by John_Moylan (jfp), 24 June 2003I can't really speak on the topic of a dedicated php editor. (I use emacs, which does me fine)
But this will help:
Select your platform & licence type, I suspect you'll want freeware and browse the varients.
Posted by admin (Graham Ellis), 24 June 2003Personally, I use vi with ":set list" to display control codes in files, and there is a PC version available even though this is very much a Linux and Unix editor. I'm also used to notepad putting up "blotches" where there are certain control codes ....
If using these editors doesn't help / they're not available, can I suggest you start a new PHP file with just the <?php and ?> in it, and cut and paste in sections of the code to narrow down the failure a bit.
By the way - I cut and pasted your code from the forum and ran it through PHP at the command line. Did exactly what I expected - no MySQL server on the test machine, so it compiled and blew at the connection:
I conclude that either it's something to do with the PHP version, or something that's in your file but not in your post (e.g. special characters!)
[Hey, jfp ... didn't mean to "overpost" you ... I think you and I were coming up with ideas at the same time!]
Posted by waygood (waygood), 1 July 2003This may help you as it simplifies executing a query a little bit.
$sql="SELECT * FROM users";
$submit=="click" ---- You should be using $_POST['submit']=="click"
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: firstname.lastname@example.org • WEB: http://www.wellho.net • SKYPE: wellho