Re: Wow, this is weird
| From: | tamouse mailing lists | Date: | Wed, 29 Aug 2012 18:33:20 +0000 |
| Subject: | Re: Wow, this is weird | ||
| References: | 1 2 3 4 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-48443@lists.php.net to get a copy of this message | ||
On Tue, Aug 28, 2012 at 6:12 AM, David McGlone <david@dmcentral.net> wrote:
> On Tuesday, August 28, 2012 12:41:19 AM you wrote:
>> Here, in your original pastebin, at line 36:
>>
>> mysql_query ("INSERT INTO inventory(image, year, make, model, milage, price)
>> VALUES('$_POST[image]', '$_POST[year]', '$_POST[make]',
>> '$_POST[model]', '$_POST[milage]', '$_POST[price]')");
>>
>> should be:
>>
>> mysql_query ("INSERT INTO inventory(image, year, make, model, milage, price)
>> VALUES('{$_FILES['image']['name']}',
>> '$_POST[year]', '$_POST[make]',
>> '$_POST[model]', '$_POST[milage]', '$_POST[price]')");
>
> This method was tried, and didn't work, it was inserting "Array[name]" into
> the db. This method was also what made me realize that $_FILES['image']
> ['name'] is being interpreted as an array. So what I did was assigned the
> value to a variable.
I think you must be missing the '{}' brackets, or something, because
with this added to the snippet from before:
$sql = "INSERT INTO inventory(image, year)
VALUES('{$_FILES['image']['name']}', '$_POST[year]')";
echo '<h2>$sql = </h2><pre>'.PHP_EOL;
var_dump($sql);
echo '</pre>'.PHP_EOL;
I get:
$sql =
string(58) "INSERT INTO inventory(image, year) VALUES('1.png',
'2012')"
which shows $_FILES['image']['name'] correctly interpolated to a string.