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