I am having problems with a data entry issue i have a field in my database which is called headline it is set to varchar 255 when i insert for example something with for eample.

The 'dogs' are very big.

the code is sent by normal $headline=$_POST["headline"]; then inserted to the database normally but what is saved keeps coming out as

The ???dogs??? are very big/

why is this why is it changing '' to ??? ???

??? Any ideas on how i can fix this issue?

9 Years
Discussion Span
Last Post by uesuva

It is because you cannot directly use quotes and some other symbols in a mysql query. To solve this you need to escape them like previously mentioned. I am guessing you would like an example so below is one:

mysql_query("INSERT INTO `table` SET `column`='".mysql_real_escape_string($_POST["headline"])."'");

Hope the visual helps.


I'm having issues as well; I have a database jokes and am trying to insert into it (the ID is auto incrementing) this is what I have, as you can see I'm trying to insert a value from a form.

$joketext = $_POST['joketext'
if ("SUBMIT" == $_POST['submitjoke']) {
  $sql = "INSERT INTO Jokes VALUES ($joketext, CURDATE())";
  if (mysql_query($sql)) {
    echo("<P>Your joke has been added.</P>");
  } else {
    echo("<P>Error adding submitted joke: " .
         mysql_error() . "</P>");

It comes back with the error Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.