vendredi 2 avril 2021

Insert Into returning error, (PHP, HTML, MYSQL)

Hey guys I am new to PHP Can you please help me with this? I don't know why I can't insert my data in MySql.

1: My HTML FORM CODE 2: PHP Snippet 3: DB view 4: Error

1: A: My HTML FORM CODE (it's working, I used UIKIT)

<form class="uk-grid-small" uk-grid action="AddProject.php" method="post" enctype="multipart/form-data" autocomplete="off">
                        <div class="uk-width-1-1">
                            <input class="uk-input uk-button-secondary" type="text" placeholder="Title" id="title" name="title" required>
                        </div>

                        <div class="uk-width-1-1">
                            <textarea class="uk-textarea uk-button-secondary" placeholder="Description" id="des" name="des" required></textarea>
                        </div>
                        <div class="uk-margin" >
                            <div uk-form-custom="target: true" class="">
                                <input class="uk-width-1-1@l uk-form-width-large" type="file" id="imageFile" accept="image/*" name="filename">
                                <input class="uk-input uk-form-width-medium" type="text" placeholder="Select image" disabled>
                            </div>



                        </div>


                        <div class="uk-margin uk-width-1-2 uk-align-right">
                            <label for="link"></label><input class="uk-input uk-button-secondary uk-form-width-large" type="url" id="link" name="link" placeholder="Website" required>
                        </div>



                        <div class="uk-margin uk-width-1-1@s">
                            <button class="uk-button uk-button-default uk-width-1-1@l uk-button-large uk-button-secondary" type="submit" value="Sum" name="Submit">Submit</button>
                        </div>
                    </form>

1: B: Form Screen Shot FORM SS

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);
                    }
                }
            }
        }



    ?>

**3: DB View **

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";  

CREATE TABLE `project` (
  `id` int(11) NOT NULL,
  `Title` varchar(50) NOT NULL,
  `Description` varchar(1000) NOT NULL,
  `Image` varchar(200) NOT NULL,
  `Site` varchar(100) NOT NULL
) 

ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

DB SS

4 : 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

Error




Aucun commentaire:

Enregistrer un commentaire