Spicing up PHP data insertion into the database

I am working with two fields: one is a textarea and the other is an image field.

<textarea name="siteplan" id="siteplan" class="form-control" rows="10"></textarea>

The image field looks like this:

<input type="file" name="image" id="image">

Here is the text that I want to insert into the textarea:

var city = new google.maps.LatLng(43.20976, -79.96596);
                var point1 = new google.maps.LatLng(43.20500, -79.96390);
        var imageBounds = new google.maps.LatLngBounds(
            new google.maps.LatLng(43.2052,-79.9684),
            new google.maps.LatLng(43.2146,-79.9627));

        var mapOptions = {
          zoom: 16,
          center: city,
          mapTypeId: google.maps.MapTypeId.HYBRID
        }

        var map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);

                var contentString = '<div id="content">'+
                        '<div id="siteNotice">'+
                        '</div>'+
                        '<div id="bodyContent">'+
                        '<p><b>Ancaster Glen</b> - 435 Garner Rd E, Ancaster</p>' +
                        '</div>'+
                        '</div>';

                var infowindow = new google.maps.InfoWindow({
                content: contentString,
                        maxWidth: 300
                });

                var marker = new google.maps.Marker({
                        position: point1,
                        map: map,
                        title:"Ancaster Glen"
                });

                google.maps.event.addListener(marker, 'click', function() {
                        infowindow.open(map,marker);
                });

        var oldmap = new google.maps.GroundOverlay(
            '/images/IMAGE.png',
            imageBounds);
        oldmap.setMap(map);

I would like to replace IMAGE.png in the above text with the name of the image uploaded through the input file field. Is this doable? Any assistance on how to achieve this would be highly appreciated.

Thank you in advance.

Answer №1

To achieve this, you can utilize the following code snippet: $updatedText = str_replace('IMAGE.png',$_FILES["image"]["name"],$_POST['siteplan']); Subsequently, insert the modified text ($updatedText) into the database.

Remember to properly filter the $text input prior to storing it in order to prevent any potential threats such as SQL injections or persistent XSS attacks.

Answer №2

A helpful tip for processing user input in PHP is to use the srt_ireplace function when dealing with content from a text area field.

Here's an example:

$siteplan=$_POST['siteplan'];
$image=$_POST['image'];
$imageName=$image["tmp_name"];
$siteplan=srt_ireplace('IMAGE.png',$imageName,$siteplan);

Remember to always sanitize and secure your input data to protect against any malicious intent from users.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Tips on extracting JSON information in JavaScript when the key name is unspecified

I have a challenge in parsing JSON data where the property name is unknown. Below is a snippet of my code, and I need your help in figuring out how to retrieve all data with an unknown property. datas.data.videoGroup.past, then utilize a loop $.each(data ...

Setting a false condition on jQuery's .on('canplaythrough') event

Struggling to implement a custom audio control with jQuery, but encountering some issues. I'm in the process of converting native JavaScript to jQuery for consistency in my code, however, I can't seem to get it working. The original code that is ...

Javascript variable unable to retrieve value from textbox

Hey there! I am having some trouble reading a textbox that is populated from the server into a JavaScript variable. When I try to access it, I get a console error saying "can't read from NULL". However, the text box is definitely populated with the st ...

Unable to fetch information from the local host using an AJAX request and PHP script

I'm having trouble retrieving the <p> elements echoed in my PHP script. I need a solution that allows me to style these <p> nodes using a JavaScript function without refreshing the page. Can someone help me with this issue? Here is my PHP ...

I am looking to share videos and large files without the use of a flash plugin

Looking for a way to upload videos without using the Flash Plugin and without relying on the browser's default browse button, especially for large files. It would be great to have a progress bar displayed during the upload process. Alternatively, is ...

Steps for properly closing the loop to input data into an array prior to populating the JSON object in Node.js

I have encountered an issue while trying to fill all the data from my loop into an array. It seems that the loop is being executed last, causing the array to remain empty when I try to print the data. var data = new Array(); for (let station of t ...

"Incorporating date and time information into the database

I am attempting to set up an automatic SMS system that sends a reminder 24 hours before our residents' appointments. My challenge lies in extracting the date and time from the datetime row in my MySQL database. While I could create an input field, my ...

Comparison Between React-Redux mapStateToProps and Inheriting Props from ParentsIn the

Excuse my lack of experience, but I am currently delving into the world of react-redux and trying to grasp the concepts as I progress. Situation: In my main component within a react-redux application, I have the following snippet at the end: function map ...

Utilizing AngularJS to invoke an ng-controller within a nested controller structure

Take a look at this sample code from the cshtml file: <div> <button type="button" ng-click="recalcButton()">Recalc Button</button> </div> <div ng-controller="appealPartialController"> < ...

Verify whether the SQL query includes a specific text, and if so, substitute it with a different one

Hello, I am a newcomer to MySql and currently using an open-source platform called GLPI that utilizes the MVC method. I have been finding it quite challenging to edit the main code within GLPI, so I am wondering if there is a way for me to modify the sel ...

Finding the names in another table that are associated with two or more rows based on their unique IDs

To set up the database and create two tables, I used the following code: DROP DATABASE IF EXISTS shop; CREATE DATABASE shop CHARACTER SET utf8mb4; USE shop; CREATE TABLE manufacturer ( id INT UNSIGNED AUTO_INCREMENT PRIMARY KEY, name VARCHAR(100) NOT ...

When the onClick event on one element triggers a change in another element within the

I apologize if the title is not clear. I have a React component with buttons and text, which I have used three times. My goal is for each button to display its respective text when clicked, while hiding the texts associated with the other buttons. While m ...

Exploring Ways to Retrieve Property Names in AngularJS JSON

I need help finding a way to use the property name as the table header in my code example below: <table> <th ng-repeat="auditorium in auditoriums"> {{ auditorium.NAME }} </th> <tbody ...

A method to apply a class to the third <li> element using javascript

Can someone help me figure out how to add a class to the third element using Javascript? Here is the structure I am working with: <ul class="products-grid row four-columns first"> <li class="item"></li> <li class="item"></li&g ...

Can anyone recommend a drag-and-drop feature in Javascript that functions seamlessly on both iPad and PC devices?

Can anyone recommend a JavaScript plugin that allows for drag and drop functionality on both touch and mouse enabled devices, including IOS, Android, PC, and Mac? For touch-enabled devices, I found an example here: And for mouse-enabled devices, there is ...

Searching for a list of inappropriate words within a database that are separated by commas

I am seeking to check if a user-submitted comment in the database contains bad words separated by commas. Database table bad_word: id words 1 word1, word2 2 word3, word4 The code I am currently using only checks for one bad word per row in the ...

Is there a way to determine if an event has been triggered by the original event that initiated it?

Consider a scenario where the following events are in play: $(button).on('mouseup', function (event1) { $(something).show(); $(document).on('mouseup', function (event2) { $(something).hide(); }); }); In this case ...

Having difficulties in storing the checkbox selections

Whenever I switch components and return back, the checkboxes do not persist. I want to ensure that the checked checkboxes stay checked. For more information and code samples, you can visit this CodeSandbox link: CodeSandbox Link. courses.js import React ...

You cannot directly access an array useState by index in React js, but you can use the map function to

export interface JobListing { id: number, isTraded: boolean, feedback: string, title: string, message: string, skills: string[], sender: string, ipAddress: string } const GroupList = () => { const [jobListings, setJobListings] = useSt ...

Manipulating objects with Jade Mixin

My current challenge involves programmatically displaying objects within a jade template by passing an array of objects to the view. The aim is to present these objects in a grid view with up to 3 items per row. However, I encountered an issue where nested ...