bertieboy_93 Posted September 17, 2006 Share Posted September 17, 2006 Hi, I'm not sure if this is a php problem or mysql problem, so sorry if this is in the wrong forum.I have a form which is used for a cms. You enter text into the form, it sends the data to a confirmation page just so you can check for any typos etc. Then it stores the data from the form into a session and passes it onto the update script when the user presses OK. Sometimes this all works great, and the entry in the database. Other times, it doesn't update. Everything is passed onto the confirmation dialogue fine, so it can't be a problem with my form. What I'm puzzled about is why it isn't always updating the database entry correctly. A lot of the time this happens when pasting from notepad, but I can't see why this would be a problem.My update script:[code]<?/*$pagename is a way of identifying which record to update in the database.$pageheading is the pageheading data retrieved from a session variable from the confirmation page.$pagetext is the pagetext data retrieved from a session variable from the confirmation page.PageHeading is varcharPageText is mediumtext*///Update database$query = "UPDATE Main SET PageHeading = '$pageheading', PageText = '$pagetext' WHERE PageName = '$pagename'";mysql_query($query);echo "Your changes on the $pagename page have been saved.";?>[/code]Thanks in advance for any help. Quote Link to comment Share on other sites More sharing options...
Wintergreen Posted September 17, 2006 Share Posted September 17, 2006 Try adding [code] or die(mysql_error());[/code]to the end of your mysql_query line. That way if there's an error it might give a hint as to what went wrong Quote Link to comment Share on other sites More sharing options...
bertieboy_93 Posted September 17, 2006 Author Share Posted September 17, 2006 Wow! Thanks for responding so quickly. I did that and have determine that the problem is about apostrophes in the text field. Is there any way of stopping mysql getting upset about apostrophes? Quote Link to comment Share on other sites More sharing options...
Wintergreen Posted September 17, 2006 Share Posted September 17, 2006 Use mysql_real_escape_string on the input and it should take care of it.If that makes it start printing extra slashes when you print the input from the DB later, use stripslashes() before you print it. For example$string = mysql_real_escape_string($string);or when you print it, $string = stripslashes($string); Quote Link to comment Share on other sites More sharing options...
bertieboy_93 Posted September 19, 2006 Author Share Posted September 19, 2006 Here is my new update script.[code]<?php//Update database$query = "UPDATE Main SET PageHeading = '$pageheading', PageText = '$pagetext' WHERE PageName = '$pagename'";$query = mysql_real_escape_string($query);$query = stripslashes($query);mysql_query($query) or die(mysql_error());?>[/code]The trouble is, at the beggining of each new line the letters rn are displayed. I don't know why this is happening.EDIT: Someone seems to be having a similar problem here:[url=http://www.phpfreaks.com/forums/index.php/topic,108657.0.html]http://www.phpfreaks.com/forums/index.php/topic,108657.0.html[/url] 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.