Jump to content

inserting into db


phpnewby1918

Recommended Posts

hi i'm trying to insert this text just "we're pleased to announce etc........ect"

 

but I can only insert "We" i believe its because single quotation mark. I've tried using addslashes, mysqli_real_escape_string and htmlspecialchars, strp_tags and applied it to my variable $s. But what ever i seem to try and insert still results in "we" being inserted. Cant see for the life of me why???

 

appreciate any help

 

if (isset($_POST['submitted'])) {

$errors = array();

if (empty($_POST['title'])) {
$errors[] = '<p class="error">Either you haven\'t filled in the title or story for this news</p>';
} else {
$t = mysqli_real_escape_string($dbc, $_POST['title']);
}
if (empty($_POST['story'])) {
$errors[] = '<p class="error">Either you haven\'t filled in the title or story for this news</p>';
} else {
$s = $_POST['story']; 
}
echo $s;

if(empty($errors)) { // No errors

$q = "INSERT INTO news (title, story, date_added) values ('$t', '$s', NOW() )";	
$r = mysqli_query($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc)); 

if (mysqli_affected_rows == !1) { // It didnt run ok
$errors[] = '<p class="error">An error occured with your upload<a href="loggedin.php"> Admin</a></p>';
} else {
echo 'Your news story has been added, visit <a href="news.php">News</a>'; 
} //if mysqli_affected rows
} else {
	echo '<p class="error">The following errors occured<br />';
		foreach ($errors as $msg) {
			echo " - $msg<br>";
			}
				echo 'Please try again';
					} // end of $errors

} // End of submitted

 

This is my code i'm using :-)

 

as you an see i'm posting the variable $s which is    ($_POST['story'];) with no functions and it still only inserts "we" nothing more?????

Link to comment
https://forums.phpfreaks.com/topic/225673-inserting-into-db/
Share on other sites

Looking more into it i type  '  into word and it doesnt create a ' it creates a curly single quotation mark. So when i copy if from word into my upload section it treats it as a different charachter to '

 

adn then the query fails.  but i've just gone and chantged the Word instances of the single quotation mark to my keyboard  ' single quotation mark and the string inserts all the way up until the next occurance of the word single quotation mark.????

 

Any ideas?

Link to comment
https://forums.phpfreaks.com/topic/225673-inserting-into-db/#findComment-1165238
Share on other sites

Looking more into it i type  '  into word and it doesnt create a ' it creates a curly single quotation mark. So when i copy if from word into my upload section it treats it as a different charachter to '

 

adn then the query fails.  but i've just gone and chantged the Word instances of the single quotation mark to my keyboard  ' single quotation mark and the string inserts all the way up until the next occurance of the word single quotation mark.????

 

Any ideas?

 

Definitely check to make sure magic quotes aren't on like BlueSky mentioned.... and NEVER EVER EVER EVER use word as an editor. It inserts all kinds of random characters that screw things up that you often can't even see. Word is not a code editor. At least use notepad instead.

Link to comment
https://forums.phpfreaks.com/topic/225673-inserting-into-db/#findComment-1165249
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.