carsey Posted October 21, 2007 Share Posted October 21, 2007 Hi, Im having a big problem with my table. The main function of the site works fine where we submit articles and they are stored in the database in MYSQL. But, if we enter a large amount of HTML to be stored, it simply throws us a internal server error preventing us from saving to the database. The database is set to longtext so the amount of characters shouldnt really be a problem. What is a solution to this problem?? Anything else needed im happy to give you it if neccessary. Chris Quote Link to comment Share on other sites More sharing options...
derwert Posted October 21, 2007 Share Posted October 21, 2007 Are you properly escaping the data? Quote Link to comment Share on other sites More sharing options...
carsey Posted October 21, 2007 Author Share Posted October 21, 2007 Hi, Well, the problem is when we are submitting content to the database, the overall submitting process works a dream, but when we are submitting a large amount of text we get the error. Here is the code: <? include "functions.php"; logincheck(); ?> <? include_once "../includes/db_connect.php"; ?> <? $cat=$_POST['cat']; $name=$_POST['name']; $articles=$_POST['articles']; $type=$_POST['type']; if ($_POST['Submit']){ mysql_query("INSERT INTO `1` (`id`, `name`, `article`, `cat`, `type`, `author`) VALUES ('', '$name', '$articles', '$cat', '$type', '$username')"); print"<p class='success'>You Added The $type, $name</p>"; } ?> <style type="text/css"> <!-- .style1 {font-family: Verdana, Arial, Helvetica, sans-serif} .success { color: #990000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: x-small; font-weight: bold; color: #009900; text-decoration: none; background-color: #FFFFFF; text-align: center; padding: 5px; border: 2px solid #000000; margin-right: 100px; margin-left: 100px; } --> </style> <link href="../style.css" rel="stylesheet" type="text/css" /> <form action="" method="post" name="form1" class="style1" id="form1"> <p align="center"> Name: <input name="name" type="text" id="name" /> </p> <p align="center">Category <select name="cat" id="cat"> <option>Hardware</option> <option> Windows</option> <option>Software</option> <option>Security</option> <option>Networking</option> <option>Alternate Computing</option> <option>Business and Career</option> <option>Gaming </select> </p> <p align="center">Type <select name="type" id="type"> <option>Article</option> <option>Tutorial</option> <option>Tips</option> </select> </p> <div align="center"> <input type="submit" name="Submit" value="Submit" /> </div> <p align="center">Articles:</p> <p align="center"> <textarea name="articles" cols="100%" rows="200" id="articles"></textarea> </p> <p align="center"> </p> </form> Hope that helps Quote Link to comment Share on other sites More sharing options...
Simon Moon Posted October 21, 2007 Share Posted October 21, 2007 Your table name is "1" ? Anyways, whats the exact error you get? Maybe some more details would be good. Like change this mysql_query("INSERT INTO `1` (`id`, `name`, `article`, `cat`, `type`, `author`) VALUES ('', '$name', '$articles', '$cat', '$type', '$username')"); into this $query = "INSERT INTO `1` (`id`, `name`, `article`, `cat`, `type`, `author`) VALUES ('', '$name', '$articles', '$cat', '$type', '$username')"; mysql_query($query) or die(mysql_error()." ".mysql_errno ()." ".$query); and post here what it spits out. As an additional thing you can add this to the top of the script, just after the <?php thing, and copy all the warnings and errors that one spits out too. error_reporting(E_ALL); Quote Link to comment Share on other sites More sharing options...
carsey Posted October 21, 2007 Author Share Posted October 21, 2007 I will try that now, and yes my table name is '1'. Thanks for your reply Quote Link to comment Share on other sites More sharing options...
carsey Posted October 21, 2007 Author Share Posted October 21, 2007 HI again. I still get the same Internal server error message Here is the message: Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, webmaster@carsey2.hosting-town.com and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request. Quote Link to comment Share on other sites More sharing options...
Simon Moon Posted October 21, 2007 Share Posted October 21, 2007 If you can get a holed of the error_log of that servers apache, that would help, check for the latest entries, there is something awfully wrong there. Looks to me like PHP wasnt compiled right or a config error. You can see html pages on that host? PHP otherwise works fine? Quote Link to comment Share on other sites More sharing options...
carsey Posted October 22, 2007 Author Share Posted October 22, 2007 PLease see attached error log. All pages on the host work fine, Including both PHP and HTML pages. See yourself via the link here: http://www.c-carse.co.uk Articles in general, if they are short, are fine and submit no problem. (see the tips section > Windows) as they all submitted no problem and the script added links etc. Its just the long articles that are failing to submit. hope this helps. Many thanks for your support thus far. Chris [attachment deleted by admin] Quote Link to comment Share on other sites More sharing options...
Simon Moon Posted October 22, 2007 Share Posted October 22, 2007 PHP Parse error: syntax error, unexpected '=' in /home/carseyh/public_html/admin/create articles.php on line 38 there is something wrong there. Other than that the error log doesnt tell me much. Quote Link to comment Share on other sites More sharing options...
carsey Posted October 22, 2007 Author Share Posted October 22, 2007 Line 38 in the create_articles.php file is CSS. border: 2px solid #000000; I dont see how that can affect the articles going into the database. Quote Link to comment Share on other sites More sharing options...
Simon Moon Posted October 22, 2007 Share Posted October 22, 2007 Ok get the site to make the error, then instantly check the error log of apache and see what it wrote in the last few lines. That should give a further clue. If you want to talk to me on MSN or icq. fenway: keep the discussion to the boards! Quote Link to comment Share on other sites More sharing options...
carsey Posted October 22, 2007 Author Share Posted October 22, 2007 Hi, This is what occurs in the error log when I submit: [Mon Oct 22 22:55:15 2007] [error] [client 86.141.248.52] File does not exist: /home/carseyh/public_html/404.shtml [Mon Oct 22 22:55:15 2007] [error] [client 86.141.248.52] File does not exist: /home/carseyh/public_html/stylesheets/online.css [Mon Oct 22 22:55:15 2007] [error] [client 86.141.248.52] File does not exist: /home/carseyh/public_html/404.shtml [Mon Oct 22 22:55:15 2007] [error] [client 86.141.248.52] File does not exist: /home/carseyh/public_html/admin/includes/in.css [Mon Oct 22 22:55:10 2007] [error] [client 86.141.248.52] File does not exist: /home/carseyh/public_html/500.shtml Please feel free to add me to MSN, if you wish. Chris Quote Link to comment Share on other sites More sharing options...
fenway Posted October 22, 2007 Share Posted October 22, 2007 Not really a mysql problem at this opint... Quote Link to comment Share on other sites More sharing options...
carsey Posted October 22, 2007 Author Share Posted October 22, 2007 Any ideas as to what it could be?? MSN: carsey2@hotmail.com fenway: keep the discussion to the boards! Quote Link to comment Share on other sites More sharing options...
fenway Posted October 22, 2007 Share Posted October 22, 2007 Well, earlier you had a parsing error, and now you have missing files. Quote Link to comment Share on other sites More sharing options...
carsey Posted October 22, 2007 Author Share Posted October 22, 2007 Well im still confused with it all.... It submits small articles fine and they view properly, its just the large ones that are failing. Quote Link to comment Share on other sites More sharing options...
derwert Posted October 23, 2007 Share Posted October 23, 2007 Are you properly escaping the data? I see no where in your code where you are properly escaping the data... So.. how about you escape your data before you put it in the database... just to eliminate that as a possible problem.. Also add some error reporting to your mysql functions.. Quote Link to comment Share on other sites More sharing options...
carsey Posted October 23, 2007 Author Share Posted October 23, 2007 How would I alter my code to escape the data?? I have even tried loading content management systems and they still produce the same error. Chris Quote Link to comment Share on other sites More sharing options...
derwert Posted October 23, 2007 Share Posted October 23, 2007 You could do something along the lines of: <?php function escape($str){ if(get_magic_quotes_gpc()) $str = stripslashes($str); return mysql_real_escape_string($str); } $cat=escape($_POST['cat']); $name=escape($_POST['name']); // etc.. ?> Also change mysql_query(...); to mysql_query(...) or die(mysql_error()); temporarily so we can see if there is any error. If escaping the data doesn't correct the issue you should still do it anyway to ensure there is no SQL injection. But if that doesn't work and you don't get an error message then it's likely that the error is being caused by some "security" module such as mod_security. Basically it tries to identify attacks by using patterns and if a pattern is matched it will stop the request and show an error page. Quote Link to comment Share on other sites More sharing options...
carsey Posted October 23, 2007 Author Share Posted October 23, 2007 I changed the file to this but im not sure whether it is correct. <? function escape($str){ if(get_magic_quotes_gpc()) $str = stripslashes($str); return mysql_real_escape_string($str); } $cat=escape($_POST['cat']); $name=escape($_POST['name']); $articles=escape($_POST['articles']); $type=escape($_POST['type']); if ($_POST['Submit']){ mysql_query("INSERT INTO `1` (`id`, `name`, `article`, `cat`, `type`, `author`) VALUES ('', '$name', '$articles', '$cat', '$type', '$username')") or die(mysql_error());; print"<p class='success'>You Added The $type, $name</p>"; } ?> Quote Link to comment Share on other sites More sharing options...
derwert Posted October 23, 2007 Share Posted October 23, 2007 is that just a snippet or the whole thing? I see some of your original code missing, most notably the file that appears to connect to your database. Quote Link to comment Share on other sites More sharing options...
carsey Posted October 23, 2007 Author Share Posted October 23, 2007 Sorry, here is the full code used in the create articles file. <? include "functions.php"; logincheck(); ?> <? include_once "../includes/db_connect.php"; ?> <? function escape($str){ if(get_magic_quotes_gpc()) $str = stripslashes($str); return mysql_real_escape_string($str); } $cat=escape($_POST['cat']); $name=escape($_POST['name']); $articles=escape($_POST['articles']); $type=escape($_POST['type']); if ($_POST['Submit']){ mysql_query("INSERT INTO `1` (`id`, `name`, `article`, `cat`, `type`, `author`) VALUES ('', '$name', '$articles', '$cat', '$type', '$username')") or die(mysql_error()); print"<p class='success'>You Added The $type, $name</p>"; } ?> <style type="text/css"> <!-- .style1 {font-family: Verdana, Arial, Helvetica, sans-serif} .success { color: #990000; font-family: Verdana, Arial, Helvetica, sans-serif; font-size: x-small; font-weight: bold; color: #009900; text-decoration: none; background-color: #FFFFFF; text-align: center; padding: 5px; border: 2px solid #000000; margin-right: 100px; margin-left: 100px; } --> </style> <link href="../style.css" rel="stylesheet" type="text/css" /> <form action="" method="post" name="form1" class="style1" id="form1"> <p align="center"> Name: <input name="name" type="text" id="name" /> </p> <p align="center">Category <select name="cat" id="cat"> <option>Hardware</option> <option> Windows</option> <option>Software</option> <option>Security</option> <option>Networking</option> <option>Alternate Computing</option> <option>Business and Career</option> <option>Gaming </select> </p> <p align="center">Type <select name="type" id="type"> <option>Article</option> <option>Tutorial</option> <option>Tips</option> </select> </p> <p align="center">Articles:</p> <p align="center"> <textarea name="articles" cols="100" rows="50" id="articles"></textarea> </p> <p align="center"> <input type="submit" name="Submit" value="Submit" /> </p> </form> Quote Link to comment Share on other sites More sharing options...
derwert Posted October 23, 2007 Share Posted October 23, 2007 And the results are? Quote Link to comment Share on other sites More sharing options...
carsey Posted October 23, 2007 Author Share Posted October 23, 2007 Same Internal error Quote Link to comment Share on other sites More sharing options...
carsey Posted October 23, 2007 Author Share Posted October 23, 2007 FIxed the problem It was the hosting. So I moved to another free host. Many many many thanks for the help guys, it was really appreciated. Highly reccomended. Chris Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.