-2

PHP

<?php
        $server_name= "localhost";
        $db_user="root";
        $db_password="";
        $db_name="digitalmarketing";

        $connection=mysqli_connect($server_name,$db_user,$db_password,$db_name);
        $dbconfig=mysqli_select_db($connection,$db_name);

        session_start();
        $_SESSION['message']='';

        if($_SERVER['REQUEST_METHOD']=='POST')
        {
            $title= mysqli_real_escape_string($connection,$_POST['title']);
            $Des= mysqli_real_escape_string($connection,$_POST['des']);
            $imagepath= mysqli_real_escape_string($connection,'Projects/'.$_FILES['filename']['name']);
            $link= mysqli_real_escape_string($connection,$_POST['link']);
            echo $title,"           ";
            echo $Des,"           ";
            echo $imagepath,"           ";
            echo $link," \n          ";

            if(preg_match("!image!",$_FILES['filename']['type'])){
                if(copy($_FILES['filename']['tmp_name'],$imagepath)){
                    $query="INSERT INTO `project` (`id`, `Title`, `Description`, `Image`, `Site`) VALUES (NULL, $title, $Des, $imagepath, $link)";
                    if(mysqli_query($connection, $query))
                    {
                        echo "success";
                    }
                    else {
                        echo "Error: " . $query . "<br>" . mysqli_error($connection);
                    }
                }
            }
        }

Error

Error: INSERT INTO project (id, Title, Description, Image, Site) VALUES (NULL, TitleHere, DescripHere, Projects/Screenshot 2021-03-18 222903.png, https://www.w3schools.com/tags/att_input_type.asp) You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '2021-03-18 222903.png, https://www.w3schools.com/tags/att_input_type.asp)' at line 1

Why am I getting this error?

Dharman
  • 30,962
  • 25
  • 85
  • 135
Anshul
  • 3
  • 5

1 Answers1

0

Change

$query="INSERT INTO `project` (`id`, `Title`, `Description`, `Image`, `Site`) VALUES (NULL, $title, $Des, $imagepath, $link)";

to

$query="INSERT INTO `project` (`id`, `Title`, `Description`, `Image`, `Site`) VALUES (NULL, '$title', '$Des', '$imagepath', '$link')";

Extra: Read about using prepared statements and use it. https://www.tutorialrepublic.com/php-tutorial/php-mysql-prepared-statements.php

ash__939
  • 1,614
  • 2
  • 12
  • 21