MySQLI- Allow the Forward Slash to be Used With Insert Statement

1.1k views Asked by At

I have a MySQL field ("imagelocation") that contains the relative pathname to an image. Essentially the construct: "DirectoryName/ImageName.png" The "/" is causing a problem. I get the error message: "Unknown column 'Analog' in 'field list'" (Analog is the name of the directory.)

Prior to building the pathname, the following code is executed to return only a "clean" image name.

$imagelocation=trim(SanitizeString($_FILES['imagevar']['name']));

The pathname is built with the following code:

$imagelocation=trim($magazinedirectory . "/" . $imagelocation);

The query to be executed:

$query="INSERT INTO tblIssueList(IssueDate,MagazineNUM,CoverArtistNUM,ImageLocation)" .
        " VALUES({$issuedate},{$magazineidnum},{$artistidnum},{$imagelocation})";

The query works when "imagelocation" is removed. The query also works with "imagelocation" when the "/" is removed.

How can the relative pathname be stored in the field "imagelocation"?

1

There are 1 answers

3
Ramy Deeb On BEST ANSWER

You forgot to quote your values in the INSERT command MySQL, will add single words for strings, and without special characters, if you add quotes, it treats all the value as an string:

$query="INSERT INTO tblIssueList(IssueDate,MagazineNUM,CoverArtistNUM,ImageLocation)" .
    " VALUES('{$issuedate}','{$magazineidnum}','{$artistidnum}','{$imagelocation}')";