i am using the following code but it seems whenever i use a single quotation (') or double quotation (") in my article field ($_POST['article']
)it is not going to be added to the database unless i use \'
or \"
so that it is read by the query as part of the text..
is there any code i can write so that it considers the $_POST['article']
as a whole text?
here is my code:
<?php
require_once ('connection.php');
$title=$_POST['title'];
$article=$_POST['article'];
if($category!="")
{
$query = "SELECT count( id ) as num FROM article;";
$result = mysqli_query($conn, $query);
/* numeric array */
$row = mysqli_fetch_array($result, MYSQLI_NUM);
if($row[0]==0)
{
$newId=0;
}else{
$query = "SELECT MAX( id ) as max FROM article;";
$result = mysqli_query($conn, $query);
/* numeric array */
$row = mysqli_fetch_array($result, MYSQLI_NUM);
$newId = $row[0] +1;
}
$sql="INSERT INTO `article`(`id`, `title`, `text`)
VALUES ('".$newId."','".$title."','".$article."')";
$result = $conn->query($sql);
if ($conn->query($sql) === TRUE) {
header("Location: ArticleSent.php");
$conn->close();
exit();
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
$conn->close();
exit();
}
}
else
{
header("Location: categoryrequired.php");
$conn->close();
exit();
}
?>