Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 13

Discussione: Struttura tabella

  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2004
    Messaggi
    323

    Struttura tabella

    Salve a tutti, io vi posto questo script che fa al caso mio, ma non so come é strutturata la tabella MySQL:

    -----------------------------
    <?php
    $conn = mysql_connect("localhost", "username", "password") or die(mysql_error());
    mysql_select_db('test', $conn) or die(mysql_error());

    if(@$_FILES['userfile']['tmp_name']){
    resize();
    $q = "INSERT INTO test VALUES ('', '".$blob_arr['image']."', '".$blob_arr['thumb']."', '".$blob_arr['type']."')";
    $aa = mysql_query($q,$conn) or die(mysql_error());

    }

    function resize(){
    global $blob_arr;
    $temp_name =$_FILES['userfile']['tmp_name'];
    $userfile_name =$_FILES['userfile']['name'];
    $userfile_size =$_FILES['userfile']['size'];
    $userfile_type =$_FILES['userfile']['type'];

    $thumb_width=90;
    $thumb_height=90;
    $image_width=300;
    $image_height=400;

    if (!($userfile_type =="image/pjpeg" OR $userfile_type =="image/jpeg" OR $userfile_type=="image/gif" OR $userfile_type=="image/png" OR $userfile_type=="image/x-png")){
    die ("You can upload just images in .jpg .jpeg .gif and .png format!<br / >");
    }
    $data = fread(fopen($temp_name, "rb"), filesize($temp_name));
    $src_image = imagecreatefromstring($data);
    $width = imagesx($src_image);
    $height = imagesy($src_image);
    if ($thumb_width && ($width < $height)) {
    $thumb_width = ($thumb_height / $height) * $width;
    } else {
    $thumb_height = ($thumb_width / $width) * $height;
    }
    if ($image_width && ($width < $height)) {
    $image_width = ($image_height / $height) * $width;
    } else {
    $image_height = ($image_width / $width) * $height;
    }
    $dest_img = imagecreatetruecolor($thumb_width, $thumb_height);
    $i_dest_img = imagecreatetruecolor($image_width, $image_height);
    imagecopyresized($dest_img, $src_image,0, 0, 0, 0,$thumb_width, $thumb_height,$width, $height);
    imagecopyresized($i_dest_img, $src_image,0, 0, 0, 0,$image_width, $image_height,$width, $height);
    ob_start();
    if($userfile_type == "image/jpeg" OR $userfile_type == "image/pjpeg"){
    imagejpeg($dest_img);
    }
    if($userfile_type == "image/gif"){
    imagegif($dest_img);
    }
    if($userfile_type == "image/png" OR $userfile_type == "image/x-png"){
    imagepng($dest_img);
    }
    $binaryThumbnail = ob_get_contents();
    ob_end_clean();
    ob_start();
    if($userfile_type == "image/jpeg" OR $userfile_type == "image/pjpeg"){
    imagejpeg($i_dest_img);
    }
    if($userfile_type == "image/gif"){
    imagegif($i_dest_img);
    }
    if($userfile_type == "image/png" OR $userfile_type == "image/x-png"){
    imagepng($i_dest_img);
    }
    $binaryImage = ob_get_contents();
    ob_end_clean();
    if(!get_magic_quotes_gpc()){
    $binaryThumbnail=addslashes($binaryThumbnail);
    $binaryImage=addslashes($binaryImage);
    }
    $blob_arr['image']=$binaryImage;
    $blob_arr['thumb']=$binaryThumbnail;
    $blob_arr['type']=$userfile_type;
    }
    if(@$_POST['submit']){
    $Rs = mysql_query("SELECT * FROM test WHERE id = '".mysql_insert_id()."'", $conn) or die(mysql_error());
    $row_Rs = mysql_fetch_assoc($Rs);
    header( "Content-type: ".$row_Rs['filetype']."");
    echo $row_Rs['thumb'];
    }else{
    ?>
    <form name="form1" method="post" enctype="multipart/form-data" action="<? echo @$PHP_SELF; ?>">
    <input id="userfile" name="userfile" type="file" />
    <input type="submit" name="submit" value="Submit" />
    </form>
    <?
    }
    ?>
    --------------------------

    Questo script server per rimpicciolire delle immagini.

  2. #2
    Utente di HTML.it L'avatar di dararag
    Registrato dal
    Jan 2008
    Messaggi
    434
    e che cosa vorresti sapere?

  3. #3
    Utente di HTML.it
    Registrato dal
    Jun 2004
    Messaggi
    323
    Vorrei sapere che campi ha la tabella.
    La tabella si chiama test e i campi?
    Sicuramente avra' un campo blob e gli altri?

    grazie di tutto

    Ho creato UNA TABELLA TEST CON I SEGUENTI CAMPI:
    ID INT(11) AUTO_INCREMENT pk
    IMAGE LONGBLOB
    THUMB LONGBLOB
    TYPE VARCHAR(255)

    Se faccio cosi' mi viene fuori un errore:
    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 '' at line 1

    Ho un errore di query, qualcuno sa perché?

    grazie

    Io mio problema é l'inserimento nel database, non riesco.

  4. #4
    Utente di HTML.it L'avatar di dararag
    Registrato dal
    Jan 2008
    Messaggi
    434
    allora, clicca su start, quindi su esegui, digita cmd e premi ok, ora scrivi
    codice:
    cd "percorso dove è installato mysql\bin"
    ora digita
    codice:
    mysql -u root -p
    quindi, quando lo chiederà, digita la tua password
    ora, per creare la tabella devi scrivere:
    prima:
    codice:
    USE database_da_usare;
    poi:
    codice:
    CREATE TABLE test (id int(11) auto_increment primary key, image longblob, thumb longblob, type varchar(255));
    mentre, per avere la descrizione dei campi, sempre scrivendo use database dove c'è la tabella da controllare:
    codice:
    describe test;
    PS: questi però sono i fondamenti di sql e di mysql, dovresti conoscerli se li utilizzi

  5. #5
    Utente di HTML.it
    Registrato dal
    Jun 2004
    Messaggi
    323
    CREATE TABLE IF NOT EXISTS `test` (
    `id` int(11) NOT NULL auto_increment,
    `image` longblob NOT NULL,
    `thumb` longblob NOT NULL,
    `type` varchar(255) NOT NULL,
    PRIMARY KEY (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=9 ;

    Questa é la mia tabella, il mio problema é che mi da' un errore nell'insert!!

    L'errore é dovuto a questo:
    $q = "INSERT INTO test VALUES ('', '".$blob_arr['image']."', '".$blob_arr['thumb']."', '".$blob_arr['type']."')";

  6. #6
    Utente di HTML.it L'avatar di dararag
    Registrato dal
    Jan 2008
    Messaggi
    434
    usa questo:
    codice:
    $q = "INSERT INTO test SET image=\"$blob_arr['image']\", thumb=\"$blob_arr['thumb']\", type=\"$blob_arr['type']\"";

  7. #7
    Utente di HTML.it
    Registrato dal
    Jun 2004
    Messaggi
    323
    Non funziona , solito errore, non riesco a capire perché

  8. #8
    Utente di HTML.it L'avatar di dararag
    Registrato dal
    Jan 2008
    Messaggi
    434
    allora, ripeti per bene, qual è l'errore (postalo per intero con il bbcode [code]), e spiega facendo cosa ti esce

  9. #9
    Utente di HTML.it
    Registrato dal
    Jun 2004
    Messaggi
    323
    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 '' at line 1
    Error 1064

    Ciao

  10. #10
    Utente di HTML.it L'avatar di dararag
    Registrato dal
    Jan 2008
    Messaggi
    434
    mi sa che non hai letto:
    Posta il codice con cui ti esce

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.