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. Link to comment https://forums.phpfreaks.com/topic/4851-insertion-into-mysql-text-field/ Share on other sites More sharing options...
kenrbnsn Posted March 13, 2006 Share Posted March 13, 2006 Please post your code. Link to comment https://forums.phpfreaks.com/topic/4851-insertion-into-mysql-text-field/#findComment-17053 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] Link to comment https://forums.phpfreaks.com/topic/4851-insertion-into-mysql-text-field/#findComment-17056 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 Link to comment https://forums.phpfreaks.com/topic/4851-insertion-into-mysql-text-field/#findComment-17061 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. Link to comment https://forums.phpfreaks.com/topic/4851-insertion-into-mysql-text-field/#findComment-17070 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. Link to comment https://forums.phpfreaks.com/topic/4851-insertion-into-mysql-text-field/#findComment-17088 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! Link to comment https://forums.phpfreaks.com/topic/4851-insertion-into-mysql-text-field/#findComment-17103 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? Link to comment https://forums.phpfreaks.com/topic/4851-insertion-into-mysql-text-field/#findComment-17134 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.