Help on adding image path to database

#1

I get it, I’m probably being obtuse here. But, can someone help me on how to add the image path to the database? I have an database insert that includes tons of info, including an image. The form is generated, and I’ve added all of the image parts I needed in the Server Side steps. (Thanks to psweb.)

But when I submit the form, nothing happens. It doesn’t upload or anything and is triggering some kind of 500 error. Am I missing a step? On the insert dialog, I added the save image as the action for the file upload field…

#2

What’s the exact error message you see in the console?

#3

HTTP500: SERVER ERROR - The server encountered an unexpected condition that prevented it from fulfilling the request.
(XHR)POST - http://localhost/dolls/dmxConnect/api/database/insertdoll.php

#4

And that file is:

 <?php
require('../../../dmxConnectLib/dmxConnect.php');


$app = new \lib\App();

$app->define(<<<'JSON'
{
  "meta": {
"options": {},
"$_POST": [
  {
    "type": "text",
    "name": "name"
  },
  {
    "type": "text",
    "name": "description"
  },
  {
    "type": "text",
    "name": "gallery"
  },
  {
    "type": "text",
    "name": "category"
  },
  {
    "type": "text",
    "name": "purchased"
  },
  {
    "type": "text",
    "name": "sold"
  },
  {
    "type": "text",
    "name": "type"
  },
  {
    "type": "text",
    "name": "species"
  },
  {
    "type": "text",
    "name": "brand"
  },
  {
    "type": "text",
    "name": "year"
  },
  {
    "type": "number",
    "name": "currentvalue"
  },
  {
    "type": "number",
    "name": "estimatedvalue"
  },
  {
    "type": "text",
    "name": "material"
  },
  {
    "type": "text",
    "name": "nrfb"
  },
  {
    "type": "text",
    "name": "unopened"
  },
  {
    "type": "text",
    "name": "condition"
  },
  {
    "type": "text",
    "name": "orginalbox"
  },
  {
    "type": "text",
    "name": "licensedbrand"
  }
]
  },
  "exec": {
"steps": [
  "Connections/connection1",
  {
    "name": "upload_product_image",
    "module": "upload",
    "action": "upload",
    "options": {
      "fields": "{{$_POST.gallery}}",
      "path": "/images",
      "replaceSpace": true,
      "replaceDiacritics": true,
      "asciiOnly": true
    },
    "meta": [
      {
        "name": "name",
        "type": "text"
      },
      {
        "name": "path",
        "type": "text"
      },
      {
        "name": "url",
        "type": "text"
      },
      {
        "name": "type",
        "type": "text"
      },
      {
        "name": "size",
        "type": "text"
      },
      {
        "name": "error",
        "type": "number"
      }
    ],
    "outputType": "array"
  },
  {
    "name": "image_loader",
    "module": "image",
    "action": "load",
    "options": {
      "path": "{{upload_product_image}}"
    },
    "outputType": "object",
    "meta": [
      {
        "name": "width",
        "type": "number"
      },
      {
        "name": "height",
        "type": "number"
      }
    ]
  },
  {
    "name": "",
    "module": "image",
    "action": "resize",
    "options": {
      "instance": "image_loader",
      "width": 1000
    }
  },
  {
    "name": "",
    "module": "image",
    "action": "crop",
    "options": {
      "instance": "image_loader",
      "x": "center",
      "y": "middle",
      "width": 700,
      "height": 700
    }
  },
  {
    "name": "save_product_image",
    "module": "image",
    "action": "save",
    "options": {
      "instance": "image_loader",
      "path": "/images",
      "overwrite": true
    },
    "output": true
  },
  {
    "name": "insertdollitem",
    "module": "dbupdater",
    "action": "insert",
    "options": {
      "connection": "connection1",
      "sql": {
        "type": "insert",
        "values": [
          {
            "table": "dolls",
            "column": "name",
            "type": "text",
            "value": "{{$_POST.name}}"
          },
          {
            "table": "dolls",
            "column": "description",
            "type": "text",
            "value": "{{$_POST.description}}"
          },
          {
            "table": "dolls",
            "column": "gallery",
            "type": "text",
            "value": "{{save_product_image}}"
          },
          {
            "table": "dolls",
            "column": "category",
            "type": "text",
            "value": "{{$_POST.category}}"
          },
          {
            "table": "dolls",
            "column": "purchased",
            "type": "text",
            "value": "{{$_POST.purchased}}"
          },
          {
            "table": "dolls",
            "column": "type",
            "type": "text",
            "value": "{{$_POST.type}}"
          },
          {
            "table": "dolls",
            "column": "species",
            "type": "text",
            "value": "{{$_POST.species}}"
          },
          {
            "table": "dolls",
            "column": "brand",
            "type": "text",
            "value": "{{$_POST.brand}}"
          },
          {
            "table": "dolls",
            "column": "year",
            "type": "text",
            "value": "{{$_POST.year}}"
          },
          {
            "table": "dolls",
            "column": "estimatedvalue",
            "type": "text",
            "value": "{{$_POST.estimatedvalue}}"
          },
          {
            "table": "dolls",
            "column": "material",
            "type": "text",
            "value": "{{$_POST.material}}"
          },
          {
            "table": "dolls",
            "column": "nrfb",
            "type": "text",
            "value": "{{$_POST.nrfb}}"
          },
          {
            "table": "dolls",
            "column": "unopened",
            "type": "text",
            "value": "{{$_POST.unopened}}"
          },
          {
            "table": "dolls",
            "column": "condition",
            "type": "text",
            "value": "{{$_POST.condition}}"
          },
          {
            "table": "dolls",
            "column": "orginalbox",
            "type": "text",
            "value": "{{$_POST.orginalbox}}"
          },
          {
            "table": "dolls",
            "column": "licensedbrand",
            "type": "text",
            "value": "{{$_POST.licensedbrand}}"
          }
        ],
        "table": "dolls",
        "query": "INSERT INTO dolls (name, description, gallery, category, purchased, type, species, brand, year, estimatedvalue, material, nrfb, unopened, condition, orginalbox, licensedbrand) VALUES (:$_POST_name, :$_POST_description, :save_product_image, :$_POST_category, :$_POST_purchased, :$_POST_type, :$_POST_species, :$_POST_brand, :$_POST_year, :$_POST_estimatedvalue, :$_POST_material, :$_POST_nrfb, :$_POST_unopened, :$_POST_condition, :$_POST_orginalbox, :$_POST_licensedbrand)",
        "params": [
          {
            "name": "$_POST_name",
            "type": "expression",
            "value": "{{$_POST.name}}"
          },
          {
            "name": "$_POST_description",
            "type": "expression",
            "value": "{{$_POST.description}}"
          },
          {
            "name": "save_product_image",
            "type": "expression",
            "value": "{{save_product_image}}"
          },
          {
            "name": "$_POST_category",
            "type": "expression",
            "value": "{{$_POST.category}}"
          },
          {
            "name": "$_POST_purchased",
            "type": "expression",
            "value": "{{$_POST.purchased}}"
          },
          {
            "name": "$_POST_type",
            "type": "expression",
            "value": "{{$_POST.type}}"
          },
          {
            "name": "$_POST_species",
            "type": "expression",
            "value": "{{$_POST.species}}"
          },
          {
            "name": "$_POST_brand",
            "type": "expression",
            "value": "{{$_POST.brand}}"
          },
          {
            "name": "$_POST_year",
            "type": "expression",
            "value": "{{$_POST.year}}"
          },
          {
            "name": "$_POST_estimatedvalue",
            "type": "expression",
            "value": "{{$_POST.estimatedvalue}}"
          },
          {
            "name": "$_POST_material",
            "type": "expression",
            "value": "{{$_POST.material}}"
          },
          {
            "name": "$_POST_nrfb",
            "type": "expression",
            "value": "{{$_POST.nrfb}}"
          },
          {
            "name": "$_POST_unopened",
            "type": "expression",
            "value": "{{$_POST.unopened}}"
          },
          {
            "name": "$_POST_condition",
            "type": "expression",
            "value": "{{$_POST.condition}}"
          },
          {
            "name": "$_POST_orginalbox",
            "type": "expression",
            "value": "{{$_POST.orginalbox}}"
          },
          {
            "name": "$_POST_licensedbrand",
            "type": "expression",
            "value": "{{$_POST.licensedbrand}}"
          }
        ]
      }
    },
    "meta": [
      {
        "name": "identity",
        "type": "text"
      },
      {
        "name": "affected",
        "type": "number"
      }
    ]
  }
]
  }
}
JSON
);
?>
#5

Can you priythe exact error as explained here: Debugging Problems

#6

Good to know. Wish it was short though. lol

{"code":0,"file":"C:\\xampp\\htdocs\\dolls\\dmxConnectLib\\lib\\core\\Path.php","line":40,"message":"Undefined offset: 0","trace":"#0 C:\\xampp\\htdocs\\dolls\\dmxConnectLib\\lib\\core\\Path.php(40): exception_error_handler(8, 'Undefined offse...', 'C:\\\\xampp\\\\htdocs...', 40, Array)\n#1 C:\\xampp\\htdocs\\dolls\\dmxConnectLib\\modules\\image.php(32): lib\\core\\Path::toSystemPath(Array)\n#2 C:\\xampp\\htdocs\\dolls\\dmxConnectLib\\lib\\App.php(159): modules\\image->load(Object(stdClass), 'image_loader')\n#3 C:\\xampp\\htdocs\\dolls\\dmxConnectLib\\lib\\App.php(128): lib\\App->execSteps(Object(stdClass))\n#4 C:\\xampp\\htdocs\\dolls\\dmxConnectLib\\lib\\App.php(98): lib\\App->execSteps(Array)\n#5 C:\\xampp\\htdocs\\dolls\\dmxConnectLib\\lib\\App.php(71): lib\\App->exec(Object(stdClass))\n#6 C:\\xampp\\htdocs\\dolls\\dmxConnect\\api\\database\\insertdoll.php(8): lib\\App->define(Object(stdClass))\n#7 {main}"}<br />
<b>Fatal error</b>:  Uncaught ErrorException: imagedestroy() expects parameter 1 to be resource, null given in C:\xampp\htdocs\dolls\dmxConnectLib\lib\image\Processor.php:25
Stack trace:
#0 [internal function]: exception_error_handler(2, 'imagedestroy() ...', 'C:\\xampp\\htdocs...', 25, Array)
#1 C:\xampp\htdocs\dolls\dmxConnectLib\lib\image\Processor.php(25): imagedestroy(NULL)
#2 [internal function]: lib\image\Processor-&gt;__destruct()
#3 {main}
  thrown in <b>C:\xampp\htdocs\dolls\dmxConnectLib\lib\image\Processor.php</b> on line <b>25</b><br />
#7

I think your image load path is wrong.
It must be the URL returned by the upload step, not the upload step itself

1 Like
#8

How do I do that?: I have a dynamic action picker with the option to choose the image upload itself or I can browse and find some sort of file. I have watched a bunch of videos on dmxzone and still can’t figure this out.

#10

After the image load step in server action you should be able to see the upload step in the picker with all it’s properties, one of which should be psth

#11

#12

That is very strange. See image below. I photoshoped this to show you what I had on my version. I was doing this on my home pc. Now I am at the office. I had no options whatsoever. And I had tried putting .path to see if that would work and it didn’t.

I have noticed that Wappler acts strangely on my home PC. I had uninstalled it yesterday and reinstalled it. And this thing came up. I wonder if there is a reason nothing would show up on the image load other than the image load itself?

#13

Are you sure you selected the proper file input in the file upload step as well?

#14

I have no idea. lol For some reason my mind is mush on this. It isn’t showing the path and stuff on this computer either.

#15

I think I figured it out. Not sure yet. But I think I’m heading in the right direction.
I noticed under Globals -> POST, it had all of the fields listed from my database. SO I clicked on the gallery one and saw it had a field reference. So I put $_POST[‘gallery’]. Then I changed the file type from text to file. NOW all the options are showing under load image.

So couple questions:

How did all those fields get under Globals -> Post automatically?
And why didn’t it just default to file since that is what is on my form?

#16

It depends on how did you create the form, how have you imported the post vars and how many times were the form and its fileds edited.
Most probably you missed something simple during the whole process of building your form.

#17

Well, actually funny thing. And I know what you’re thinking Teodor: “My Lord, this Chad guy is a genius of amazing proportions.” But, I hate to burst your amazement. Alas, I’m not.

When I was working on the modals, I would have it open, reformat the form, and to close it, I would click this red x up in the top right. (See screenshot below.) ANd I would save, and preview in browser and nothing would work. My modal wouldn’t even pop up. So, then I’d go outside and smoke a cigarette, and come back. Accept my modal wasn’t there anymore. So I would rebuild it, reformat it, and all of this all over again.

SO I did that cycle probably 10 times. Well, turns out that red x isn’t to close the modal. It is to delete it! lol

Oh. I almost drunk myself stupid after that realization last night.

1 Like