Продолжаю попытки запустить скрипт.
На данный момент запрос выглядит таким образом:
INSERT INTO `image`
SET `type` = '".($_FILES['userFile '][' TYPE '])."',
`name` = '".($_FILES['userFile ']['name '])."',
`alt` = '".($alt)."',
`img` = '".($image)."'
База отвечает вот как:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'userFile']['type'])."', `name` = '".($_FILES['userFile']['name'])."', `alt` = ' at line 2Понимаю, что проблема в синтаксисе, но от синтаксиса мускуля я ещё слишком далёк, чтобы понять чего оно хочет.
Из формы код тоже не выполняется,
пруфВ данный момент весь скрипт такой:
<?php mysql_connect('************','***************','***********');
mysql_select_db('************');
error_reporting(-1);
ini_set('display_errors',1); ?>
<html><body>
<h1>Uploading Images to MySQL</h1><p>
<?php
if ( !isset($_FILES['userFile']['type']) )
{
die('<p>No image submitted</p></body></html>');
}
?>
You submitted this file:<br /><br />
Temporary name: <?php echo $_FILES['userFile']['tmp_name'] ?><br />
Original name: <?php echo $_FILES['userFile']['name'] ?><br />
Size: <?php echo $_FILES['userFile']['size'] ?> bytes<br />
Type: <?php echo $_FILES['userFile']['type'] ?></p>
<?php
if (isset($_POST['picup'])) {
if ( !preg_match( '/gif|png|x-png|jpeg/', $_FILES['userFile']['type']) ) {
die('<p>Не тот формат</p></body></html>'); }
else if ( strlen($_POST['altText']) < 9 ) {
die('<p>Текст надобно подлиннее</p></body></html>'); }
else if ( $_FILES['userFile']['size'] > 160384 ) {
die('<p>Файл надобно помельче</p></body></html>'); }
// Copy image file into a variable
else if ( !($handle = fopen ($_FILES['userFile']['tmp_name'], "r")) ) {
die('<p>Error opening temp file</p></body></html>'); }
else if ( !($image = fread ($handle, filesize($_FILES['userFile']['tmp_name']))) ) {
die('<p>Error reading temp file</p></body></html>'); }
else {
fclose ($handle);
// Commit image to the database
$image = mysql_real_escape_string($image);
$alt = htmlentities($_POST['altText']);
$query = ("
INSERT INTO `image` SET
`type` = '".($_FILES['userFile']['type'])."',
`name` = '".($_FILES['userFile']['name'])."',
`alt` = '".($alt)."',
`img` = '".($image)."',
");
if ( !mysql_query($query)) {
die('<p>Error writing image to database</p></body></html>');
} else {
die('<p>Image successfully copied to database</p></body></html>');
}
}
}
?>
</body></html>