DELETE in mysql

giancadeejay

Utente Attivo
26 Ott 2010
224
0
16
torino
Buongiorno a tutti
Carico un immagine in tabella db mysql e vorrei poterla cancellare dove imageId risulti uguale a username ,
Mi date una mano ...non so dove sbaglio
cancella.php
PHP:
    $conn = mysql_connect("localhost", "user", "");
    mysql_select_db("my_db");
    $sql = "DELETE imageId FROM output_images WHERE imageId = $username";
    $result = mysql_query($sql);

    mysql_close($conn);
 
Ultima modifica di un moderatore:

macus_adi

Utente Attivo
5 Dic 2017
1.343
91
48
IT/SW
Ciao @giancadeejay ,
la query per eliminare non è cosi
$sql = "DELETE imageId FROM output_images WHERE imageId = $username";

ma cosi

PHP:
$sql = "DELETE  FROM output_images WHERE imageId = $username";


Ti conviene utilizzare l'estensione mysqlì
PHP:
$host='localhost';
$uset='utente';
$pass='pass';
$database='nome_db';
//connessione
$conn=new mysqli($host,$user,$pass,$database);
//query
$q="DELETE FROM TABELLA WHERE userID = $utente";
//esecuzione query
$conn->query($q);
 

giancadeejay

Utente Attivo
26 Ott 2010
224
0
16
torino
Ciao Marcus_adi e grz per la risposta ma non elimina la riga dell'utente loggato...
PHP:
<?php
session_start();
if(!isset($_SESSION['utente'])){
    //una o entrambe le sessioni non esistono
    if(isset($_SESSION))session_destroy();
    header('location:http://MIOSITO.org');// o altrove
    exit();
}else{
    //le sessioni esistono
?>
<?php

$conn = mysql_connect("localhost", "USER", "");
    mysql_select_db("my_DB");
    $username = $_SESSION['utente'];
    $sql = "DELETE FROM output_images WHERE imageId = $username";
    $result = mysql_query($sql);

    mysql_close($conn);

?>

<?php
}
?>

Non capisco perche' non cancella la riga dell'utente..
Mi aiutate?
 

macus_adi

Utente Attivo
5 Dic 2017
1.343
91
48
IT/SW
Sicuro che SESSION['utente'] contenga lo stesso valore del campo imageId? magari esiste qualche spazio prova a trimmare la stringa utente...


Prova a fare
Codice:
SELECT * FROM tabella WHERE userId = $userid
vedi cosa ti esce
 

giancadeejay

Utente Attivo
26 Ott 2010
224
0
16
torino
sicuro
L'INSERT FUNZIONA
DB.jpg
 
Ultima modifica:

giancadeejay

Utente Attivo
26 Ott 2010
224
0
16
torino
upload.php
Codice:
session_start();
if(!isset($_SESSION['utente'])){
    //una o entrambe le sessioni non esistono
    if(isset($_SESSION))session_destroy();
    header('location:http://sito.org');// o altrove
    exit();
}else{
    //le sessioni esistono
?>
<?php
if(count($_FILES) > 0) {
if(is_uploaded_file($_FILES['userImage']['tmp_name'])) {
    mysql_connect("localhost", "user", "");
    mysql_select_db ("my_db");
    $username = $_SESSION['utente'];
    $imgData =addslashes(file_get_contents($_FILES['userImage']['tmp_name']));
    $imageProperties = getimageSize($_FILES['userImage']['tmp_name']);
    
    $sql = "INSERT INTO output_images(username,imageType ,imageData)
    VALUES('{$username}','{$imageProperties['mime']}', '{$imgData}')";
    $current_id = mysql_query($sql) or die("<b>Error:</b> Problem on Image Insert<br/>" . mysql_error());
    if(isset($current_id)) {
        header("Location: listImages.php");
    }
}
}
?>
<HTML>
<HEAD>
<TITLE>Upload Image to MySQL BLOB</TITLE>
<link href="imageStyles.css" rel="stylesheet" type="text/css" />
</HEAD>
<BODY>
<form name="frmImage" enctype="multipart/form-data" action="" method="post" class="frmImageUpload">
<label>Upload Image File:</label><br/>
<input name="userImage" type="file" class="inputFile" />
<input type="submit" value="Submit" class="btnSubmit" />
</form>
</div>
</BODY>
</HTML>
<?php
}
?>
 
Discussioni simili
Autore Titolo Forum Risposte Data
I Problema con DELETE - MYSQL PHP 6
L Delete record mysql PHP 0
novello88 [MySQL] Delete Record (cancellare una riga) MySQL 1
M query update e delete PHP 0
Jensen Errore di sintassi con DELETE PHP 3
R query DELETE non cancella i record PHP 1
Cosina Creare bottone delete in form upload PHP 5
Cosina Creare bottone delete in form upload PHP 1
Y query di DELETE PHP 4
Alex_70 Delete foto in database e cartella PHP 72
1 Errore UPDATE, DELETE MS Access 16
D Query di delete tra due tabelle MySQL 1
M DELETE record di due tabelle MySQL 1
F Delete record database PHP 6
pup3770 Automatizzare Istruzione DELETE FROM attivazione automatica PHP 4
H DELETE su una tabella e INSERT SULL'ALTRA... PHP 1
R query delete e ID progressivo.. PHP 2
borgo italia delete where data< PHP 3
borgo italia delete from PHP 2
A Insert,Delete e Update file di testo PHP 0
grottafelix Finestra Alert prima di delete Classic ASP 0
K form Inserimento record mysql PHP 2
P Mysql lento a cancellare MySQL 1
P Codifica caratteri speciali mysql php PHP 0
N MAX() + ADD_DATE - per update su Mysql MySQL 0
F Applicazione PHP/MySQL per prenotazioni: limitare il numero massimo di posti prenotabili PHP 20
L tipo boolean non funzionante su mariadb (mysql). E codice php 7.4. PHP 0
M PHP/MySQL - Estrarre valori min e max di ogni gruppo PHP 5
W MySQL ciclo in SELECT MySQL 0
L Mysql gestionale multipiattaforma MySQL 0
W MySQL SELECT list dinamica MySQL 0
M utilizzo mysql in nodejs - crea createdAt e updateAt MySQL 1
T colonne di tabelle mysql ordinate MySQL 0
M Sintassi "personalizzata" per mysql workbench? MySQL 0
A Mysql MySQL 0
F Ricreare struttura php+mysql su Xampp Apache 0
M Array associativi php su 2 campi mysql PHP 10
Z Controllo giorni MYSQL PHP 0
L php mysql non salva solo id PHP 21
L php mysql cerca e visualizza pagina PHP 0
L Mysql: Nascondere le pagine dopo una ricerca PHP 1
R Aggiornare record mysql con Ajax, jQuery e php Ajax 2
S problema con recupero dati tabella mysql PHP 2
E Progressbar estrazione dati da tabella mySQL Ajax 9
Z MySql injection PHP PHP 1
D controllare valore in tabella mysql PHP 0
A pulsante di update campo mysql con javascript Javascript 2
R Tutto su utf-8 ma ancora problemi con i caratteri speciali in mysql MySQL 1
T differenza fra mysql xampp e un mysql server Database 0
R Importazione csv su mysql tramite array PHP 2

Discussioni simili