Jump to content

' Character wont allow me to write record to database


agentm

Recommended Posts

Not sure where to post this question. I have a MySQL database and add records with a PHP form to the tables.

 

I have 2 fields (char) in one table. When the fields contain the character '  it wont write the record to the table! For example...if I enter. " John's house" it wont accept the record since ' appears in John's name!

 

How do I work around this?

 

Thanks

Link to comment
Share on other sites

Thanks for the quick response! Im not sure where to put the code. Here is my code.

$text and $newsbox will need to be modified.

 

 

      $text = $_POST['subject'];

      $newsbox = $_POST['newsbox'];

      $sql = "INSERT INTO newslines (Subject, Newsline, Date) VALUES ('$text', '$newsbox', '$Date')"; 

Link to comment
Share on other sites

Did you read the manual page I posted? msql_real_escape_string

 

With your code, you are not protected against malicious people...

<?php
      $text = $_POST['subject'];
      $newsbox = $_POST['newsbox'];
      $sql = "INSERT INTO newslines (Subject, Newsline, Date) VALUES ('$text', '$newsbox', '$Date')"; 
?>

 

Do this:

<?php
      $text = mysql_real_escape_string($_POST['subject']);
      $newsbox = mysql_real_escape_string($_POST['newsbox']);
      $sql = "INSERT INTO newslines (Subject, Newsline, Date) VALUES ('$text', '$newsbox', '$Date')";
?>

 

Where is the variable $Date being set?

 

Ken

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.