Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > Beginning PHP
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old August 21st, 2003, 02:58 AM
Authorized User
 
Join Date: Jun 2003
Location: , , Germany.
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to insert textarea content into MySQL?

Hi there,

I have a first script which contains a form and a textarea. So now when I process the form I use something like this

Code:
$category = $HTTP_POST_VARS['name_of_category'];
$dt_question = $HTTP_POST_VARS['dt_frage'];
$eng_question = $HTTP_POST_VARS['eng_frage'];
$ratio = $HTTP_POST_VARS['rationale'];

...
$sql = "INSERT INTO sqlserverfaq (
    category, dt_question, eng_question, answer) VALUES(
    '$category', '$dt_question', '$eng_question', '$ratio')";
...
'rationale' is the textarea. Answer is the MySQL field of text data type. When I look at the results it works fine except for the content of $ratio.

So, how can I insert the content of a textarea into a MySQL text field ?

Cheers,
Frank
__________________
-----------------------
--Frank
http://www.insidesql.de
-----------------------
Reply With Quote
  #2 (permalink)  
Old August 21st, 2003, 05:06 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try inserting an:

echo $sql;

...prior to attempting to execute the query and feed the output into your MySQL database directly (via the command-line client, PHPMyAdmin, or whatever you're using). IThe DBM will probably spit out a fairly self-explanatory error message. You shouldn't need to specify field names anyway, when performing an INSERT.

HTH
Dan

Quote:
quote:Originally posted by a5xo3z1
 Hi there,

I have a first script which contains a form and a textarea. So now when I process the form I use something like this

Code:
$category = $HTTP_POST_VARS['name_of_category'];
$dt_question = $HTTP_POST_VARS['dt_frage'];
$eng_question = $HTTP_POST_VARS['eng_frage'];
$ratio = $HTTP_POST_VARS['rationale'];

...
$sql = "INSERT INTO sqlserverfaq (
    category, dt_question, eng_question, answer) VALUES(
    '$category', '$dt_question', '$eng_question', '$ratio')";
...
'rationale' is the textarea. Answer is the MySQL field of text data type. When I look at the results it works fine except for the content of $ratio.

So, how can I insert the content of a textarea into a MySQL text field ?

Cheers,
Frank
Reply With Quote
  #3 (permalink)  
Old August 21st, 2003, 05:22 AM
Authorized User
 
Join Date: Jun 2003
Location: , , Germany.
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

echo $sql; looks like I expect it to be.
However it doesn't work

I guess I'll still with phpMyAdmin which my ISP provides :-(

Cheers,
Frank
Reply With Quote
  #4 (permalink)  
Old August 21st, 2003, 06:05 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

What's the error message it gives you when you feed it directly to the MySQL server (I mean when you feed it into the box called "execute query" or something along those lines, in the PHPMyAdmin interface, and hit the "go" button)?

Dan
Reply With Quote
  #5 (permalink)  
Old August 21st, 2003, 06:12 AM
Authorized User
 
Join Date: Jun 2003
Location: , , Germany.
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

No error message

phpMyAdmin inserts just fine. The only difference I've noticed right now, is , that phpMyAdmin puts ``around each field name. Could this cause the problems?


Cheers,
Frank
Reply With Quote
  #6 (permalink)  
Old August 21st, 2003, 06:33 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Not single quotes, methinks... backticks :) (look beside the "1" key on the top row of your keyboard - on a UK-style PC keyboard at least).

Gotta dash. TTYL.
Reply With Quote
  #7 (permalink)  
Old August 21st, 2003, 06:44 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: , , United Kingdom.
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Sorry for the delay in getting back to you (Boss called me away while I was in thye middle of replying).

PHPMyAdmin is just being paranoid. The backtickls aren't necessary, and are just being added for extra insurance, I think. You'd put backticks around fieldnames wherever they contain reserved words from the SQL language, spaces, etc. It doesn't hurt to put them around fieldnames where they aren't necessary, vut it doesn't add anything either (no doubt someone will now come along with benchmark statistics which in fact prove that their use either adds or removeds several nanoseconds from the execution of the query;).

However, regardless of that, they shouldn't have any effect upon the success or failure of the query in this case.

This is proving to be a puzzler...

Dan
Reply With Quote
  #8 (permalink)  
Old August 21st, 2003, 07:39 AM
Authorized User
 
Join Date: Jun 2003
Location: , , Germany.
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

That's the phpMyAdmin Code
Code:
INSERT INTO `sqlserverscript` ( `id` , `category` , `description` , `explanation` , `scripttext` ) 
VALUES (
'', '2', 'Korrumpiert eine Datenbank (Vorsicht !!! )', NULL , 'sp_configure allow, 1 go reconfigure with override
go update sysindexes set FirstIAM = 1234
where id = OBJECT_ID(\'roysched\')go
sp_configure allow, 0 go reconfigure with override go'
);
..and that's mine
Code:
INSERT INTO sqlserverscript ( `id`,`category`, `description`, `explanation', `scripttext`) 
VALUES 
( '', '2', 'Skript, um eine Datenbank zu korrumpieren', NULL, 'sp_configure allow, 1 go reconfigure with override
go update sysindexes set FirstIAM = 1234
where id = OBJECT_ID(\'roysched\')go
sp_configure allow, 0 go reconfigure with override go');
I'm blind at the moment

Cheers,
Frank
Reply With Quote
  #9 (permalink)  
Old August 21st, 2003, 11:18 AM
Friend of Wrox
Points: 2,570, Level: 21
Points: 2,570, Level: 21 Points: 2,570, Level: 21 Points: 2,570, Level: 21
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: San Diego, CA, USA
Posts: 836
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well, at first glance your two queries seem to be identical, so I don't know what the problem is.

My only suggestion is that you might need to escape any characters that might screw up the query. Try using addslashes()

$ratio = addslashes($_POST['rationale']);

Also notice the use of $_POST instead of $HTTP_POST_VARS. Always always always use the newer $_xxx versions of the older, deprecated $HTTP_xxx_VARS!

If you're still having problems, feel free to post a structure dump of your table and any useful PHP code for us to recreate the scenario on our end.


Take care,

Nik
http://www.bigaction.org/
Reply With Quote
  #10 (permalink)  
Old August 22nd, 2003, 01:53 AM
Authorized User
 
Join Date: Jun 2003
Location: , , Germany.
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Still trying to figure it out.
addslashes didn't do the trick
changing to $_POST either
Right now I'm busy, I'll come back on monday in case I didn't solve this problem.

Thanks for everyone who responded! :)

Cheers,
Frank
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
change content of textarea from select darkhalf Javascript 1 April 26th, 2007 06:03 AM
Insert Excel sheet content into Access table from stepdev Access VBA 2 December 8th, 2006 04:18 PM
Displaying textarea content to html table keithc Pro PHP 2 December 1st, 2006 03:12 AM
How to insert text into panel with out textarea JOptionPane Java GUI 5 May 6th, 2005 03:35 PM



All times are GMT -4. The time now is 05:53 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.