I have a normal HTML-File that give a string via. POST to my PHP-file wich will put this to a MySQL-database.
How do I achieve that I can write a "real" NULL
in the database and not " " (a empty string) or something like that?
The MySQL column is nullable.
My form:
<form method="post" action="putInDatabase.php">
<label>Text</label>
<textarea name="text" ></textarea>
<label>Picture URL (optional)</label>
<input name="image" />
<br>
<input id="submit" name="submit" type="submit" value="submit">
</form>
My PHP-File:
<?php
$text = "";
$image = null;
if (isset($_POST["submit"]))
{
$text = $_POST["text"];
$image = $_POST["image"];
}
$text = strtr ($text, array ('"' => '\"'));
$con = mysql_connect("censored :)");
if (!$con)
{
die('ERROR' . mysql_error());
}
mysql_select_db("_DATABASE_HERE_", $con);
$insertSQL = "INSERT INTO `_DATABASE_HERE_`.`_NAME_HERE_` (`Text`, `PictureURL`) VALUES ('$text', '$image ');";
$res = mysql_query($insertSQL);
$res = mysql_query($sql);
mysql_close($con);
echo "Success!";
?>