HTML in database

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I am writing code to store a bunch of email files, in MIME format, into a database.  The body of some of these emails, but not all, are in HTML format.  If I use addslashes (after checking get_magic_quotes_gpc()), the database record won't get saved.  There's no error message, just no record saved.  But if I use htmlentities(), it saves the record no problem.

I would have thought that addslashes would have been enough to format the data correctly.  Why would I need to use htmlentities?  And will using htmlentities cause me any problems?

here's the code in question:

			$from = $this->SentFrom();
			$to = $this->To();
			$cc = $this->Cc();
			$subject = $this->Subject();
			$body = htmlentities($this->Body());   // this works
			//$body = $this->Body();

			if (get_magic_quotes_gpc() == 0)
			{
				echo "<br>adding slashes...";
				$body = addslashes($body);   // this runs but doesn't work
			}

			$sql = "insert emails(projectid, mailfrom, mailto, mailcc, subject, body) values(1, '$from', '$to', '$cc', '$subject', \"$body\")";
						
			echo "<br>sql:<pre><code>$sql</code></pre>";
			
			$link = mssql_connect($server, $user, $pwd)
							or die('Could not connect: ' . mysql_error());							
			mssql_select_db('EmailDB') or die('Could not select database');
			
			try
			{
				$result = @mssql_query($sql);
			}
			catch (Exception $e)
			{
			    echo "<br>Error: " . $e->getMessage;
			}


Thanks.



Regards,

Bruce

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux