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

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')"; 

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

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.