|
|
|
|
![]() ![]() |
Dec 15 2005, 12:49 AM
Post
#1
|
|
|
NiGHTFoX - Hiding in the dark Group: Members Posts: 680 Joined: 3-April 05 Member No.: 3,584 |
Ok, because I am feeling dangerous and ready to move to the next level, I wrote a simple "page generator" script for my website for several reasons:
1. I hate updating 20+ pages by hand just for ONE little template change 2. I'm expanding my PHP & MySQL knowledge... Here is an error I get on the page that is supposed to submit contents to the database: Parse error: parse error, unexpected T_VARIABLE in /home/coco563/public_html/beta/make_page/make_page.php on line 11 Now, on make_page.php, line 11 & 12 (where I feel the problem) is the following: CODE $sql = "INSERT INTO `".$tableprefix."regpage` (`id`, `title`, `content`) VALUES ('"$_POST['id']"', '"$_POST['title']"', '"$_POST['content']"');"; mysql_query($sql); Also, can someone show me the proper way to make a database? I feel the way I did it must have caused the error. Thanks! [N]F This post has been edited by miCRoSCoPiC^eaRthLinG: Dec 15 2005, 03:51 AM |
|
|
|
Dec 15 2005, 01:54 AM
Post
#2
|
|
|
Super Member Group: Members Posts: 572 Joined: 25-April 05 From: Nashville Tennessee Member No.: 4,340 |
What is your table prefix and is is defined somewhere like in a configuration file that accesses your database. I would look something like the below
CODE $dbhost = "localhost"; $dbuname = "root"; $dbpass = ""; $dbname = "78"; $tableprefix = "somePrefix"; $user_prefix = "somePrefix"; $dbtype = "MySQL"; The $prefix could be the variable that it doesn't find because it is not referenced or defined elsewhere. The SQL or PHP you have is valid. |
|
|
|
Dec 15 2005, 03:41 AM
Post
#3
|
|
|
PsYcheDeLiC dR3aMeR Group: Admin Posts: 2,242 Joined: 29-January 05 From: Nakorn Chaisri, Thailand Member No.: 2,411 myCENTs:84.36 |
QUOTE(nightfox @ Dec 15 2005, 07:49 AM) Here is an error I get on the page that is supposed to submit contents to the database: Parse error: parse error, unexpected T_VARIABLE in /home/coco563/public_html/beta/make_page/make_page.php on line 11 Now, on make_page.php, line 11 & 12 (where I feel the problem) is the following: CODE $sql = "INSERT INTO `".$tableprefix."regpage` (`id`, `title`, `content`) VALUES ('"$_POST['id']"', '"$_POST['title']"', '"$_POST['content']"');"; mysql_query($sql); [N]F The problem is most definitely here. In PHP, whenever that parse error, unexpected T_VARIABLE kind of message - be sure that it's a problem with either quotes - single or double - not ending/ending prematurely or a similar case with paranthesis (, { or [. Look at your code carefully: CODE $sql = "INSERT INTO `".$tableprefix."regpage` (`id`, `title`, `content`) VALUES ('"$_POST['id']"', '"$_POST['title']"', '"$_POST['content']"');"; Notice that your second " (double quotes) start from "regpage ..... '" - upto right before $_POST. See how it terminates the string right there leving $_POST attached like a tail to the string before that - but the intrepreter is unable to parse $_POST, as to it, it appears as, "........"$_POST - which doesn't make any sense. The confusion between ' (single) and " (double) quotes is always a BIG issue for any newcomer and even I've faced the same situation as you're facing today. That's why when it comes to quote symbols I learnt to be extra careful and split out my string as clearly as possible - even if it takes more typing to do. Here's what your string should look like: CODE $sql = "INSERT INTO `" . $tableprefix . "regpage` ( `id`, 'title`, `content` ) VALUES ( '" . $_POST['id'] . "', '" . $_POST ['title'] . "', '" . $_POST ['content'] . "' );"; See how I've extracted the variables that were to be evaluated and put into the string - and plugged them in separately. Since PHP parses any variable-name that begins with a $ and enclosed within double quotes, an alternative approach would be: CODE $sql = "INSERT INTO `$tableprefix`.`regpage` ( `id`, `title`, `content` ) VALUES ( '$_POST ['id']', '$_POST['title']', '$_POST['content']' )"; Hope this helps. Regards, m^e P.S. Keep in mind that if your string begins with a " (double) quote - it HAS to end with a double too - and so for the single. Always match up your quotes and see which is getting messed up of ending the string prematurely. |
|
|
|
Dec 15 2005, 04:57 AM
Post
#4
|
|
|
NiGHTFoX - Hiding in the dark Group: Members Posts: 680 Joined: 3-April 05 Member No.: 3,584 |
Thanks m^e! I seem to miss things like that... once, I had a post-it note with a big semicolon drawn on it with a sharpie so I'd remember to add one at the end of the lines because that was mainly the biggest problem for me.
Thanks again! Time to check it out and see how well it works! [N]F |
|
|
|
Dec 15 2005, 05:28 AM
Post
#5
|
|
|
NiGHTFoX - Hiding in the dark Group: Members Posts: 680 Joined: 3-April 05 Member No.: 3,584 |
Ok! I finally got it working, except my database table is bad (I don't know how to properly make one) as I guessed on how to do it. I set-up a test page here:
http://www.coconutproject.com/beta/make_pa...ge.html?ID=test Yes, images are broken, I know. I saved it into one too many directories on my server (I try to keep my local machine looking like my server). The only problem I have is that NOTHING show up. I need a TABLE made for me that only includes the following: -id -title -content ID is NOT a number... when you make a page in the admin area, you specify what you want, like "somepage" and this is what goes in the URL to call the proper content from the database. Thanks! [N]F |
|
|
|
Dec 15 2005, 07:39 AM
Post
#6
|
|
|
PsYcheDeLiC dR3aMeR Group: Admin Posts: 2,242 Joined: 29-January 05 From: Nakorn Chaisri, Thailand Member No.: 2,411 myCENTs:84.36 |
Try this:
CODE CREATE TABLE tablename ( `id` VARCHAR ( max_number_of_chars ) NOT NULL, `title` VARCHAR ( max_number_of_chars ) NOT NULL, `content` TEXT NOT NULL, PRIMARY KEY (`id`) ); That should get the proper table up for you. Don't forget to change the max_number_of_chars to whatever maximum characters you want for each field. |
|
|
|
Dec 15 2005, 09:04 PM
Post
#7
|
|
|
NiGHTFoX - Hiding in the dark Group: Members Posts: 680 Joined: 3-April 05 Member No.: 3,584 |
Thanks m^e! I don't know what I would do without your assistance with MySQL! Looks like I may need to sit down and actually read my MySQL & mSQL book even though it is a few years old...
[N]F |
|
|
|
Dec 15 2005, 11:26 PM
Post
#8
|
|
|
NiGHTFoX - Hiding in the dark Group: Members Posts: 680 Joined: 3-April 05 Member No.: 3,584 |
boy do I feel stupid... ok, my page.html (I have my server set to parse .html as .php) won't display... how do I get it to properly dislplay content from the database?
For example, a sample URL with sample data in the database is http://www.coconutproject.com/page.html?ID=sample The tutorial I followed isn't very helpful as I have modded the system into page management since I couldn't find anything like it. The original tutorial is here if it provides any help to you: http://www.pixelfull.com/tutorials.php?tutorial=view&id=8 Anyway, I need to have it where it checks the "ID" string and it looks up in the database for that ID. Once it gets that I need it to grab the title of the page and the page content. This is where I keep having my problems. I can get the page to not error out, but NOTHING is displayed out of the database. Thanks! [N]F |
|
|
|
Dec 17 2005, 05:54 AM
Post
#9
|
|
|
PsYcheDeLiC dR3aMeR Group: Admin Posts: 2,242 Joined: 29-January 05 From: Nakorn Chaisri, Thailand Member No.: 2,411 myCENTs:84.36 |
Dude you need two books - these two have been my indispensible companions in respect of MySQL and PHP.
You get these two books - you nip your coding nightmares right in the bud I'm going for a bath - will come back and post some code that might help you sort out your problem |
|
|
|
Dec 17 2005, 07:02 AM
Post
#10
|
|
|
NiGHTFoX - Hiding in the dark Group: Members Posts: 680 Joined: 3-April 05 Member No.: 3,584 |
Thanks for the book suggestions! I'll look into them. I have several books that don't help much (wrong subject matter, if I needed to create a login system and a links database, I'd be perfect!
Thanks again m^e! You've been VERY helpful! [N]F |
|
|
|
![]() ![]() |
Similar Topics
|
Lo-Fi Version | Time is now: 22nd November 2008 - 11:40 PM |