rish1103 Posted March 13, 2006 Share Posted March 13, 2006 I'm trying to write a simple blog script. Basically a varchar(255) title and a text field for the blog entry and it works for short one line entries. everytime the entry is more than two lines, nothing is entered into database and i also donot receive any error messages or anything. Can anyone suggest anything. Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 13, 2006 Share Posted March 13, 2006 Please post your code. Quote Link to comment Share on other sites More sharing options...
rish1103 Posted March 13, 2006 Author Share Posted March 13, 2006 [!--quoteo(post=354570:date=Mar 13 2006, 12:18 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Mar 13 2006, 12:18 PM) [snapback]354570[/snapback][/div][div class=\'quotemain\'][!--quotec--]Please post your code.[/quote]That's the form I use for making the entry into the blog.[code] <form action="blogin.php" method="post"> <font face="Arial" size="2"> <input type="text" name="title" size = "60" value ="Title"><br> <input type="text" name="date" value="YYYY-MM-DD"><br> <textarea rows="20" name="entry" cols="60">Make Entry Here</textarea> <br> <input type="Submit"></font> </form>[/code]Thats the script that enters the form data into the database. Like i said simple form and simple action. I am unable to understand whats wrong.[code]<?$username="######";$password="######";$database="######";$title=$_POST['title'];$date=$_POST['date'];$entry=$_POST['entry'];mysql_connect(localhost,$username,$password);@mysql_select_db($database) or die( "Unable to select database");$query = "INSERT INTO blog VALUES ('','$title','$date','$entry')";mysql_query($query);print "<font face=\"Arial\">Thankyou for submitting your information! <a href=\"../index.php\">Click here to return home</a></font>";mysql_close();?>[/code] Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted March 13, 2006 Share Posted March 13, 2006 I would add some error checking and a minimal amount of data screening:[code]<?php$title=mysql_real_escape_string($_POST['title']);mysql_connect(localhost,$username,$password);@mysql_select_db($database) or die( "Unable to select database");if ($_POST['date'] != '') { $tmp = strtotime($_POST['date']); if ($tmp == -1) date = '0000-00-00'; else $date = date('Y-m-d',$tmp); }else $date = '0000-00-00';$entry=mysql_real_escape_string($_POST['entry']);$query = "INSERT INTO blog VALUES ('','$title','$date','$entry')";mysql_query($query) or die('Problem with insert query: ' . $query . '<br />' . mysql_error());?>[/code]The date checking code will allow your users to input any valid date. (not tested)Ken Quote Link to comment Share on other sites More sharing options...
rish1103 Posted March 13, 2006 Author Share Posted March 13, 2006 [!--quoteo(post=354578:date=Mar 13 2006, 12:41 PM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Mar 13 2006, 12:41 PM) [snapback]354578[/snapback][/div][div class=\'quotemain\'][!--quotec--]I would add some error checking and a minimal amount of data screening:[code]<?php$title=mysql_real_escape_string($_POST['title']);mysql_connect(localhost,$username,$password);@mysql_select_db($database) or die( "Unable to select database");if ($_POST['date'] != '') { $tmp = strtotime($_POST['date']); if ($tmp == -1) date = '0000-00-00'; else $date = date('Y-m-d',$tmp); }else $date = '0000-00-00';$entry=mysql_real_escape_string($_POST['entry']);$query = "INSERT INTO blog VALUES ('','$title','$date','$entry')";mysql_query($query) or die('Problem with insert query: ' . $query . '<br />' . mysql_error());?>[/code]The date checking code will allow your users to input any valid date. (not tested)Ken[/quote]cool I'll add what you mentioned and see what I end up with. Quote Link to comment Share on other sites More sharing options...
rish1103 Posted March 13, 2006 Author Share Posted March 13, 2006 Is it possible there could be something wrong with my MySQL isntallation? I've never had this problem before. I tried what was mentioned here and it didnt help. the I downloaded a blog script from hotscripts to try and its the same with that as well. I'm relly stuck. Quote Link to comment Share on other sites More sharing options...
keeB Posted March 13, 2006 Share Posted March 13, 2006 [!--quoteo(post=354605:date=Mar 13 2006, 07:01 PM:name=rish1103)--][div class=\'quotetop\']QUOTE(rish1103 @ Mar 13 2006, 07:01 PM) [snapback]354605[/snapback][/div][div class=\'quotemain\'][!--quotec--]Is it possible there could be something wrong with my MySQL isntallation? I've never had this problem before. I tried what was mentioned here and it didnt help. the I downloaded a blog script from hotscripts to try and its the same with that as well. I'm relly stuck.[/quote]Probably not.. if you can connect to your database there's not a problem..Please replace the following with your mysql_query and repost the results:[code]mysql_query($query) or die('Problem with insert query: ' . $query . '<br />' . mysql_error());[/code]Hopefully this will give us a more accurate guess as to what the problem is! [=GOOD LUCK! Quote Link to comment Share on other sites More sharing options...
rish1103 Posted March 13, 2006 Author Share Posted March 13, 2006 the error returned comes up where it encounters the first single quote or ' how do i cure that and find out which ohter characters can cause a query to fail? 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.