Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How Do I Insert A Large Amount Of HTML In A MySql Database

Status
Not open for further replies.

xBadCasex

Programmer
Jun 12, 2007
5
US
I have a variable that contains a large amount of scraped html code and I would like to insert it into a mysql database.

I can echo or print the variable no problem but when I try inserting it into the database it seems to be null.
 
Hi

Show us how you try that. Also give us details about the table field in which you try to put the HTML document. ( If is possible please cut off the irrelevant parts from the code before posting. )

Feherke.
 
OK I have a variable called $bc which contains a very long string of html that has been scraped from another page.

I have 2 mysql query's in a row the first one works fine the second one that uses the $bc variable doesn't but also returns no errors.

this one works

mysql_query("INSERT INTO elggwidget_data (widget, name, value) VALUES($widget_id, 'widget_text_title', 'test title')");


this one doesnt

mysql_query("INSERT INTO elggwidget_data (widget, name, value) VALUES($widget_id, 'widget_text_body', $bc)");

I know the $bc variable is not empty because if I do

echo $bc;

it displays the page stored in the variable. I have tried various php functions like htmlentities($bc) but nothing has worked.
 
Also as a work around if you know a php function to load the entire contents of a text file into a specified table and row that would also be a workable solution for me.
 
I am sorry for all the posts my son is screaming and I cant gather my thoughts the field is named value and is set to Text utf8_unicode_ci but I can change that if needed
 
Hi

xBadCasex said:
I have tried various php functions like htmlentities($bc) but nothing has worked.
Have you tried mysql_real_escape_string() too ?
Code:
mysql_query("INSERT INTO elggwidget_data (widget, name, value) VALUES($widget_id, 'widget_text_body', [red]'".mysql_real_escape_string([/red]$bc[red])."'[/red])");
By the way, in reality you have quotes around the $bc varible, right ?

Feherke.
 
Well I tried but used it improperly thanks for your help it worked like a charm.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top