problema sintassy nella mia query

fredd

Nuovo Utente
1 Mar 2010
15
0
0
ciao a tutti,premesso che non e' che sia una cima nella programmazione,
sto studiando e provando questa semplice fotogallery.
L'upload ed il ridimensionamento funzionano ma la query non inserisce i dati sul database.

Mi restituisce questo messaggio:
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 'desc, user, pic_time) VALUES (''animationbolle0073', '14349', '128', '96', '.jpe' at line 1


se qualcuno ha voglia di darci un'occhiata questa e' la pagina uploader:

<?php
//percorsi cartelle per il caricamento dei file
include('config.php');

function get_filename($img)
{
if(!$img) return false;
$badTag = array(' ', '.', ',', '/', '`', ';', '[', ']', '-', '_', '*', '&', '^', '%', '$', '#', '@', '!', '~', '+', '(', ')', '|', '{', '}', '<', '>', '?', ':', '"', '=' );
$clean = trim(strtolower($img));
$filename = substr($clean, 0, strrpos($clean, '.'));
$img_name = str_replace($badTag, '', $filename);
return $img_name;
}

$open = opendir($upload) ;
while (false !== ($read=readdir($open)))
{
if($read != "Thumbs.db")
{
if(is_file($upload . $read))
{
$array_file[ ] = get_filename($read);
}
}
}
//visualizza il modulo di caricamento file
if(isset($_POST['submit']))

{
$mime_type = $_FILES['data']['type'];
$filename = get_filename($_FILES['data']['name']);

//verifica le dimensioni del file caricato
if($_FILES['data']['size'] == 0 )
{
die ('Errore : campo upload nullo');
}
//array delle estensione permesse
$file_permessi = array("image/gif", "image/pjpeg", "image/jpeg", "image/x-png", "image/png");
//confronto l'estensione con quelle permesse
if (!in_array($mime_type, $file_permessi))
{
die ('Etsensione non consentita');
}
//confronto il file con quelli presenti nella cartella di caricamento
if($array_file != NULL)
{
if(in_array($filename, $array_file )) die ('Esiste gia` un\' immagine con questo nome');
}
//ottiene larghezza e altezza dell'originale
list($width, $height) = getimagesize($_FILES['data']['tmp_name']);
//calcola le proporzioni e ottiene dimensioni thumbsnail
if ($width < $thumb_size && $height < $thumb_size)
{
$newwidth = $width;
$newheight = $height;
}
else
{
$newwidth = ($width > $height) ? $thumb_size : ($thumb_size / $height) * $width;
$newheight = ($height > $width) ? $thumb_size : ($thumb_size / $width) * $height;
}
//crea la nuova immagine

switch($mime_type)
{
case 'image/pjpeg':
case 'image/jpeg':
$new_img = imagecreatefromjpeg($_FILES['data']['tmp_name']);
$ext = '.jpeg';
break;
case 'image/x-png':
case 'image/png':
$new_img = imagecreatefrompng($_FILES['data']['tmp_name']);
$ext = '.png';
break;
case 'image/gif';
$new_img = imagecreatefromgif($_FILES['data']['tmp_name']);
$ext = '.gif';
break;
}

//funzione per ridimensionare l'immagine
if (function_exists('imagecreatetruecolor'))
{
$resized_img = imagecreatetruecolor($newwidth, $newheight);
imagecopyresampled($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}
else
{
$resized_img = imagecreate($newwidth, $newheight);
imagecopyresized($resized_img, $new_img, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
}
//creazione thumb
switch($mime_type)
{
case 'image/pjpeg':
case 'image/jpeg':
imagejpeg($resized_img, $thumbs . '/' .$filename .$ext, 100);
break;
case 'image/x-png':
case 'image/png':
imagealphablending($resized_img, false);
imagesavealpha($resized_img, true);
imagepng($resized_img, $thumbs . '/' .$filename . $ext);
break;
case 'image/gif';
imagegif($resized_img, $thumbs . '/' .$filename . $ext);
break;
}
imagedestroy($resized_img);
imagedestroy($new_img);


if(!is_uploaded_file($_FILES['data']['tmp_name']))
{die('Erroe nel caricamento');
}
$move = move_uploaded_file($_FILES['data']['tmp_name'], $upload . $filename . $ext)
or die('Non posso caricare il file');
if($move)
{
$sql_ary = array(
'filename' => $filename,
'filesize' => $_FILES['data']['size'],
't_width' => $newwidth,
't_height' => $newheight,
'ext' => $ext,
'title' => $_POST['title'],
'desc' => $_POST['desc'],
'user' => $_POST['user']);
$fields = $values = array();
foreach($sql_ary as $key => $value)
{
$fields[] = $key;
$values[] = "'" . mysql_real_escape_string($value) . "'";
}
$str_ary = implode(', ' , $values);
$str_key = implode(', ', $fields);

$sql = "INSERT INTO gallery (filename, filesize, t_width, t_height, ext, title, desc, user, pic_time) VALUES ('$str_ary', NOW())";
mysql_query($sql) or die(mysql_error());


echo "file caricato con successo<br />";
echo "Antemprima: <img src=\"$thumbs/$filename$ext\" />";
}
else echo 'errore';
}
?>

Grazie mille,ciao..
 

borgo italia

Super Moderatore
Membro dello Staff
SUPER MOD
MOD
4 Feb 2008
16.046
150
63
PR
www.borgo-italia.it
ciao
così ad una prima occhiata:
tu dici di inserire ben 9 campi
$sql = "INSERT INTO gallery (filename, filesize, t_width, t_height, ext, title, desc, user, pic_time) VALUES ('$str_ary', NOW())";
ma poi dai solo due valori
$sql = "INSERT INTO gallery (filename, filesize, t_width, t_height, ext, title, desc, user, pic_time) VALUES ('$str_ary', NOW())";
 

fredd

Nuovo Utente
1 Mar 2010
15
0
0
ciao,in realta la query originale e':
$sql = "INSERT INTO gallery ($str_key, pic_time) VALUES ($str_ary, NOW())";

dove se ho capito bene la variabile $str_key e' un'array contenente i campi della tabella e $str_ary e` l'array dei valori ottenuti dal form.
Avevo provato a immettere direttamente i valori contenuti in $str_key.
Si immagino che non sia stata una genialata ma sto andando un po` alla cieca onestamente.

Grazie per l'interesse
 

fredd

Nuovo Utente
1 Mar 2010
15
0
0
ciao grazie anche a te dell'aiuto.
inserendo il var_dump($sql) mi dice questo:
string(179) "INSERT INTO gallery (filename, filesize, t_width, t_height, ext, title, desc, user, pic_time) VALUES ('lato', '58407', '109.22666666667', '128', '.gif', '', 'wsws', 'wdsw', NOW())" 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 'desc, user, pic_time) VALUES ('lato', '58407', '109.22666666667', '128', '.gif',' at line 1

sbaglio a credere che il problema riguardi il campo "title"? riesci a capirci qualcosa di piu` concreto?

ciao..
 

softhare

Utente Attivo
11 Feb 2010
57
0
0
Friuli
www.softhare.it
DESC è una parola riservata!

Il problema lamentato da sql è che la parola DESC non può venire usata come nome di un campo perchè serve come parola chiave dell'ordinamento inverso (ORDER BY xyz DESC).
Per questo motivo ricevi quell'errore.

Comunque lo script non funzionerà perchè che ne sono altri...
 

fredd

Nuovo Utente
1 Mar 2010
15
0
0
Grandeee..
in effetti ,rinominando in descr l'input del form ed il campo della tabella, ora tutto funziona.

grazie mille
 
Discussioni simili
Autore Titolo Forum Risposte Data
I Sto progettando nuovi siti utilizzando bootstrap e devo dire funziona bene, l'unico problema e la maschera -moz- HTML e CSS 0
K Problema form update PHP 2
O problema con dvr dahua xvr5116 IP Cam e Videosorveglianza 0
S Problema nel ciclare un json Javascript 0
G Problema con Xampp Web Server 1
andrea barletta Problema con miniature comandi Photoshop 0
I problema con alice Posta Elettronica 0
K Problema Inner join PHP 1
F firefox problema http Linux e Software 0
N Problema con position absolute e overflow HTML e CSS 4
E Problema jquery Success jQuery 2
L Problema con inner join PHP 11
K [php] Problema con inner join PHP 4
E problema selezione sfumata Photoshop 2
K [PHP] Problema con variabili concatenate. PHP 1
A Problema filtro fluidifica Photoshop Photoshop 1
H Problema Bordi Scontorno Photoshop 1
O problema con query PHP 4
R Problema installazione Realtek WiFi USB rtl8821 Reti LAN e Wireless 0
I problema con 2 account Posta Elettronica 1
L problema collegamento file css con html HTML e CSS 1
Y Problema percorso file in rete PHP 1
N Problema SEO "L'URL non si trova su Google" SEO e Posizionamento 4
E Problema accesso a file con app sviluppata con MIT APP INVENTOR 2 Sviluppo app per Android 0
P Problema acquisizione clienti Webdesign e Grafica 1
F NetBeans problema creazione progetto Java Windows e Software 0
M Problema con Try Catch PHP 0
C problema seo + cerco esperto SEO e Posizionamento 11
Sergio Unia Problema con gli eventi del mouse su una data table: Javascript 2
T PROBLEMA CON SESSIONI PHP 3
A Problema, non so, di scale() o transform, oppure altro? HTML e CSS 0
T ALTRO PROBLEMA CON ARRAY PHP PHP 1
R problema con else PHP 0
T PROBLEMA CON ARRAY PHP 8
L problema con query select PHP 2
R Problema query con ricerca id numerico PHP 2
F Problema con risposta PHP 0
S problema con recupero dati tabella mysql PHP 2
Z Problema con il mio tp-l i nk Reti LAN e Wireless 1
I PROBLEMA: Sostituzione sito XAMPP E-Commerce 0
T problema data 30/11/-1 PHP 0
L Problema RAM con Tomcat 8 Apache 0
napuleone problema con sort e asort PHP 4
Y Problema incolonnamento tabella PHP 7
S problema salvataggio immagini Photoshop 0
Z Problema con INT MySQL PHP 1
Z Problema database MySQL con XAMPP PHP 0
M Problema con controllo form in real time jQuery 6
D problema php mysql PHP 1
D problema php mysql PHP 1

Discussioni simili