This question already has answers here:
How to insert a php code snippet in mysql database
                                
                                    (3个答案)
                                
                        
                                4年前关闭。
            
                    
如果我与我的cms人员发布了一个脚本,则无法读取该脚本,它将作为文本进入数据库

像这样:



<script>
			// Source: http://www.backalleycoder.com/2011/03/20/link-tag-css-stylesheet-load-event/
			var loadCSS = function(url, callback){
				var link = document.createElement('link');
				link.type = 'text/css';
				link.rel = 'stylesheet';
				link.href = url;
				link.id = 'theme-style';

				document.getElementsByTagName('head')[0].appendChild(link);

				var img = document.createElement('img');
				img.onerror = function(){
					if(callback) callback(link);
				}
				img.src = url;
			}

			$(document).ready(function() {
				var initEditor = function() {
					$("textarea").sceditor({
						plugins: 'bbcode',
						style: "./minified/jquery.sceditor.default.min.css"
					});
				};

				$("#theme").change(function() {
					var theme = "./minified/themes/" + $(this).val() + ".min.css";

					$("textarea").sceditor("instance").destroy();
					$("link:first").remove();
					$("#theme-style").remove();

					loadCSS(theme, initEditor);
				});

				initEditor();
			});
		</script>





但是我如何使它可以在网站上阅读?

我使用以下mysql查询:



INSERT INTO categorie (title, longstory, shortstory, date, author, categorie, type,img) VALUES('{$title}','" . htmlspecialchars_decode($longstory) . "','{$shortstory}','" . time() . "','". $_SESSION['user']['username'] ."','{$categorie}','{$type}','{$img}')";





我过去经常发布脚本:" . htmlspecialchars_decode($longstory) . "

最佳答案

要转义数据库(字符串/文本)输入,请使用mysql(i)_real_escape_string

当您将此代码放到网站上时,在输出上使用htmlspecialchars

关于php - mysql如何发布脚本,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30662284/

10-11 22:33
查看更多