Jump to content

Data won't be saved onto mysql database


bertieboy_93

Recommended Posts

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 varchar
PageText 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.
Link to comment
Share on other sites

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);
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.