Jump to content

[SOLVED] Losing Data Somehow


bluebyyou

Recommended Posts

I have a basic form to add, edit, delete my websites news from my database. For some when I access the info in my edit form, everything after  apostrophes in my title  gets lost. It does not happen in the content field.  I am doing addslashes() on info going in, and stripslashes() on everything coming out. I'm posting this here because I don think its a mysql problem. Any Ideas?

 

Here is the edit stuff..

$slashed_content = addslashes($_POST['content']);
$slashed_title = addslashes($_POST['title']);
$query = "UPDATE news SET news_title = '$slashed_title', news_content = '$slashed_content', news_active = '$_POST[active]' WHERE news_id = '$_POST[id]'";
$update_result = mysql_query($query);

 

 

Here is where I grab it form the DB

$slashed_content = addslashes($_POST['content']);
$slashed_title = addslashes($_POST['title']);
$query = "UPDATE news SET news_title = '$slashed_title', news_content = '$slashed_content', news_active = '$_POST[active]' WHERE news_id = '$_POST[id]'";
$update_result = mysql_query($query);
header ('location:index.php');
}
else
{
$news_id = $_GET['id'];

$query = "SELECT * FROM news WHERE news_id = $news_id";
$news_result = mysql_query($query);


	function edit_news($news_result)
	{
		$row = mysql_fetch_array($news_result, MYSQL_ASSOC);

		$print_date = date('F j, Y', strtotime($row['news_date']));

		echo "<h2>Edit News</h2>";
		echo "<form action='$_SERVER[php_SELF]' method='post'>" ;
		echo "<input type='hidden' name='action' value='edit'>";
		echo "<input type='hidden' name='id' value='".$row['news_id']."'>";
		echo $print_date."    <input name='title' type='text' value='".stripslashes($row['news_title'])."'>   &nbsp"; 
		echo "<input name='active' type='radio' value='0'"; 
		if ($row['news_active'] == 0) {echo "checked";}
		echo "/>Hidden";
		echo "<input name='active' type='radio' value='1'"; 
		if ($row['news_active'] == 1) {echo "checked";}
		echo "/>Active<br /><br />";
		echo "<textarea cols='80' rows='10' name='content'>".stripslashes($row['news_content'])."</textarea><br /><br />";
		echo "<input name='edit' type='submit' value='Edit'> <a href='index.php'>Cancel</a>";
		echo "</form>";
	}

 

Link to comment
https://forums.phpfreaks.com/topic/126668-solved-losing-data-somehow/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.