Cancellare amicizia

sappe

Nuovo Utente
27 Mar 2011
27
0
0
Ho dei problemi con la cancellazione delle amicizie. Cos'ho fatto? Per sistemare la visualizzazione delle amicizie l'ho divisa concettualmente in due parti (fa schifo da vedere lo so, ma funziona): amicizie che l'utente connesso ha richiesto e le amicizie che l'utente connesso ha ricevuto.
PHP:
<?php 
include ("connessione.inc");
$nickname = $_SESSION['login'];
$sql="SELECT IDutente FROM utenti WHERE Nickname = '$nickname'";
$res=mysql_query($sql, $conn) or die("Error!".mysql_error());
while ($records = mysql_fetch_assoc($res)){
$IDutente=$records['IDutente'];
echo "<h3>Friends to whom you asked the friendship:</h3>";
$sql1="SELECT nickname FROM utenti WHERE IDutente = ANY (SELECT Receiver AS amico FROM amicizie WHERE (Sender = '$IDutente') AND (Friend = '1'))";
$res1 = mysql_query($sql1, $conn) or die("Error!".mysql_error());
while ($records = mysql_fetch_assoc($res1)){
$friendA=$records['nickname'];
   echo <<<MESS
</br>$friendA</br>
<a href="deleteFriend.php?friendA=$friendA">Delete Friend</a><hr />
</br>
MESS;
}

echo "<h3>Friends who have called for the friendship:</h3>";
$sql2="SELECT nickname FROM utenti WHERE IDutente = ANY (SELECT Sender AS amico FROM amicizie WHERE (Receiver = '$IDutente') AND (Friend = '1'))";
$res2 = mysql_query($sql2, $conn) or die("Error!".mysql_error());
while ($records = mysql_fetch_assoc($res2)){
$friendB=$records['nickname'];
   echo <<<MESS
</br>$friendB</br>
<a href="deleteFriend.php?friendB=$friendB">Delete Friend</a><hr />
MESS;
}
}
?>
tutto si stampa e tutto va bene.
Nel momento in cui mi sono ritrovata a non saper bene gestire questa situazione, difatti mi sa che sto facendo una confusione tremenda nelle query:
PHP:
<?php 
include ("connessione.inc");
$nickname = $_SESSION['login'];
$sql3="SELECT IDutente FROM utenti WHERE Nickname = '$nickname'";
$res3=mysql_query($sql3, $conn) or die("Error!".mysql_error());
while ($records = mysql_fetch_assoc($res3)){
$IDutente=$records['IDutente'];
}
$sql= "SELECT * FROM amicizie WHERE (Sender = '$IDutente') or (Receiver = '$IDutente')";
$res=mysql_query($sql,$conn)or die("Error!".mysql_error());
while ($records=mysql_fetch_assoc($res)) {
   $username = $_SESSION['login'];
	 }
$sql1="DELETE FROM amicizie WHERE (Receiver='$IDutente' or Sender='$IDutente') AND (Receiver='$friendA' or Sender='$friendA') OR (Receiver='$friendB' or Sender='$friendB')";
$res1=mysql_query($sql1,$conn)or die("Error!".mysql_error());
while($records=mysql_fetch_assoc($res1)){
$friendA=$_POST["friendA"];
$friendB=$_POST["friendB"];
}
   echo "You and $friendA$friendB are no longer friend.";
	 echo "Come back to <a href=friend.php>friend</a> page.";

?>
mi restituisce una ovviamente lunghina lista di errori:
PHP:
Notice: Undefined variable: friendA in C:\Program Files\EasyPHP-5.3.2\www\Sito\deleteFriend.php on line 75

Notice: Undefined variable: friendA in C:\Program Files\EasyPHP-5.3.2\www\Sito\deleteFriend.php on line 75

Notice: Undefined variable: friendB in C:\Program Files\EasyPHP-5.3.2\www\Sito\deleteFriend.php on line 75

Notice: Undefined variable: friendB in C:\Program Files\EasyPHP-5.3.2\www\Sito\deleteFriend.php on line 75

Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\Program Files\EasyPHP-5.3.2\www\Sito\deleteFriend.php on line 77

Notice: Undefined variable: friendA in C:\Program Files\EasyPHP-5.3.2\www\Sito\deleteFriend.php on line 81

Notice: Undefined variable: friendB in C:\Program Files\EasyPHP-5.3.2\www\Sito\deleteFriend.php on line 81
You and are no longer friend.Come back to friend page.
non so come risolvere, mi sa che sto sbagliando anche la logica... Sono fusa e non ci sto capendo più niente! Mi aiutate per favore? :(
Grazie per la pazienza!!
 

sappe

Nuovo Utente
27 Mar 2011
27
0
0
Ho fatto dei cambiamenti

Siccome non mi ritrovavo più nel ragionamento che avevo fatto ho scisso la parte della cancellazione in due parti, esattamente come logicamente avevo scisso le amicizie ricevute da un utente e quelle che l'utente connesso invia. Non funzionano, proprio non agiscono sul database (non cancellano l'amicizia) anche se non danno errori e restituiscono la stringa giusta. Ricapitolando:
Pagina dove stampo la lista degli amici e che contiene il link che dà l'input per cancellare l'amicizia:
PHP:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<?php 
session_start();
?>
<HTML>
<HEAD>
<TITLE>Your Friends</TITLE><link href="style.css" rel="stylesheet" type="text/css">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
</HEAD>
<BODY>
<div align="center">
  <TABLE class="maintable" CELLPADDING="0" CELLSPACING="0">
    <TR> 
      <TD COLSPAN=3> <IMG SRC="images/index_01.gif" WIDTH=727 HEIGHT=240 ALT=""></TD>
    </TR>
    <TR> 
      <TD ROWSPAN=2 class="navbg" valign="top"><div id="nav">
          <p><span class="h2">Menu</span> <a href="index.php">Home</a> <a href="rules.php">Rules</a> 
            <a href="gallery.php">Gallery</a> <a href="upload.php">Upload</a> <a href="search.php">Search</a>
            <span class="endbox"></span> </p>
						
         
					
<?php 
if ((isset($_SESSION['login']))&&((isset($_SESSION['password'])))){
   echo <<<print
	 
	 <p><span class="h2">Logout</span> <a href="profile.php">Your Profile</a> <a href="logout.php">Logout</a><span class="endbox"></span> </p>
         <p><span class="h2">Friendship</span> <a href="users.php">Search user</a> <a href="friend.php">My friends</a> <a href="request.php">Friends request</a> <span class="endbox"></span> </p>
print;
}
else {
   echo <<<print
	 
	 <p><span class="h2">Sign in</span> <a href="create.html">Create account</a> <a href="login.htm">Login</a><span class="endbox"></span></p>
print;
}
 ?>
<?php 
include("connessione.inc");
if (isset($_SESSION['login'])) { 
    $login = $_SESSION['login']; 
$sqlA="SELECT Nickname FROM utenti WHERE Nickname = '$login' AND Admin = '1'";
$resA=mysql_query($sqlA,$conn)or die("Error!".mysql_error());
$lines=mysql_num_rows($resA);
if ($lines == 1){
 echo <<<print
	 
	 <p><span class="h2">Admin</span> <a href="admin.php">Administration</a><span class="endbox"></span></p>
print;
}
}
echo <<<print

 </p>
        </div></TD>
      <TD ROWSPAN=2 class="contentbg" valign="top"><div id="content">
print;
 ?>
          <h1>Friend page:</h1>
<h2 align="center">Your friends:</h2>
<?php 
include ("connessione.inc");
$nickname = $_SESSION['login'];
$sql="SELECT IDutente FROM utenti WHERE Nickname = '$nickname'";
$res=mysql_query($sql, $conn) or die("Error!".mysql_error());
while ($records = mysql_fetch_assoc($res)){
$IDutente=$records['IDutente'];
echo "<h3>Friends to whom you asked the friendship:</h3>";
$sql1="SELECT nickname FROM utenti WHERE IDutente = ANY (SELECT Receiver AS amico FROM amicizie WHERE (Sender = '$IDutente') AND (Friend = '1'))";
$res1 = mysql_query($sql1, $conn) or die("Error!".mysql_error());
while ($records = mysql_fetch_assoc($res1)){
$friendA=$records['nickname'];
   echo <<<MESS
</br>$friendA</br>
<a href="deleteFriendA.php?friendA=$friendA" onclick="return confirm('Do you really want to delete $friendA from your friends?')">Delete Friend</a><hr />
</br>
MESS;
}

echo "<h3>Friends who have called for the friendship:</h3>";
$sql2="SELECT nickname FROM utenti WHERE IDutente = ANY (SELECT Sender AS amico FROM amicizie WHERE (Receiver = '$IDutente') AND (Friend = '1'))";
$res2 = mysql_query($sql2, $conn) or die("Error!".mysql_error());
while ($records = mysql_fetch_assoc($res2)){
$friendB=$records['nickname'];
   echo <<<MESS
</br>$friendB</br>
<a href="deleteFriendB.php?friendB=$friendB" onclick="return confirm('Do you really want to delete $friendB from your friends?')">Delete Friend</a><hr />
MESS;
}
}
?>	
 </p>

				</p>

          </br>
					</br>
					</br>
					</br>
          <h1>©SketchMania</h1>
			<TD valign="top" class="spacer"></TD>
    </TR><TR> 
      <TD height="2" class="spacer2"></TD>
    </TR><TR> 
      <TD COLSPAN=3 class="creditsbg">
				<p>| Contact us <a href="http://yahoo.com/" target="_blank">[email protected]</a> | </p></TD>
    </TR>
  </TABLE>
</div>
</BODY>
</HTML>
Pagina dove cancello l'amico A:
PHP:
<?php 
include ("connessione.inc");
$nickname = $_SESSION['login'];
$friendA=$_GET["friendA"];

$sql3="SELECT IDutente FROM utenti WHERE Nickname = '$nickname'";
$res3=mysql_query($sql3, $conn) or die("Error!".mysql_error());
while ($records = mysql_fetch_assoc($res3)){
$IDutente=$records['IDutente'];
}

 
$sql1="DELETE FROM amicizie WHERE (Sender='$IDutente') AND (Receiver='$friendA')";
$res1=mysql_query($sql1,$conn)or die("Error!".mysql_error());

   echo "You and $friendA are no longer friend.";
	 echo "</br>Come back to <a href=friend.php>friend</a> page.";

?>
Pagina dove cancello l'amico B:
PHP:
<?php 
include ("connessione.inc");
$nickname = $_SESSION['login'];
$friendB=$_GET["friendB"];

$sql3="SELECT IDutente FROM utenti WHERE Nickname = '$nickname'";
$res3=mysql_query($sql3, $conn) or die("Error!".mysql_error());
while ($records = mysql_fetch_assoc($res3)){
$IDutente=$records['IDutente'];
}

 
$sql1="DELETE FROM amicizie WHERE (Receiver='$IDutente') AND (Sender='$friendB')";
$res1=mysql_query($sql1,$conn)or die("Error!".mysql_error());

   echo "You and $friendB are no longer friend.";
	 echo "</br>Come back to <a href=friend.php>friend</a> page.";

?>	
 </p>
Perché non funziona? Sembra cancellarlo ma non succede niente nel database!
Grazie in anticipo dell'aiuto! :D
 

sappe

Nuovo Utente
27 Mar 2011
27
0
0
Stampa le query tipo:

PHP:
$sql1="DELETE FROM amicizie WHERE (Sender='$IDutente') AND (Receiver='$friendA')"; 
echo $sql1;
Stampa la cosa giusta, ovvero:
PHP:
DELETE FROM amicizie WHERE (Receiver='47') AND (Sender='liquirizia')
se controllo nel database infatti l'utente connesso è 47 colui che ha inviato l'amicizia è liquirizia, e non ci sono cose strane nel database come doppi o cose del genere... Non capisco :S
 

micio86

Utente Attivo
E se

Prova a fare

PHP:
$query="SELECT * FROM amicizie WHERE Receiver='47' AND Sender='liquirizia'";  
$query=mysql_query($query);
echo "NUMERO DI RIGHE: ".mysql_num_rows($query);

Se ti da 0 righe allora sbagli la query.
 
Ultima modifica:
Discussioni simili
Autore Titolo Forum Risposte Data
matteoraggi Come cancellare le colonne di wordpress WordPress 0
P Mysql lento a cancellare MySQL 1
Cosina Cancellare una specifica email da un elenco in un file txt PHP 3
S Cancellare una riga MYSQL PHP 1
G Con Microsoft Outlook 2016 come si possono cancellare le mail doppie? Posta Elettronica 0
Cosina [PHP] Cancellare una riga da un file di testo in base al nome PHP 2
Cosina [PHP] Cancellare una riga da un file txt in base alla data PHP 1
L conferma prima di cancellare con javascript e php PHP 16
H cancellare avatar in codice PHP PHP 2
M [PHP] Cancellare singolo file da cartella su server PHP 3
A [PHP] Cancellare riga database a scelta dell'utente PHP 2
trattorino [PHP] sql aggiungere dato in una tabella senza cancellare contenuto PHP 6
C Cancellare un elemento del DOM jQuery 4
D [PHP] CANCELLARE MAILPLAN PHP 2
Trapano [PHP] Cancellare file da una cartella.... PHP 5
ste80 [PHP] cancellare/aggiornare record DB PHP 24
K [PHP] Cancellare e Stampare tabella PHP 3
felino [PHP] Cancellare directory con file al suo interno PHP 2
A Cancellare righe vuote in mysql Database 4
L Cancellare web site Weebly CMS (Content Management System) 0
G Pagina facebook da cancellare Social Media Marketing 4
JackIlPazzo Sostituire una riga specifica in un file di testo senza cancellare il rimanente PHP 13
M Cancellare record a tempo con formato data mktime PHP 7
E cancellare immagini che non sono nel db mysql PHP 1
max_400 Cancellare le prime 3 righe di un file PHP 4
voldemort Cancellare un file con 0 byte Java 1
A Cancellare record su più tabelle con PHP PHP 27
filippino Come cancellare dati da un database MySQL? Database 1
IImanuII Cancellare righe doppie e ciclo. PHP 2
O Cancellare dati da una tabella mysql in modo automatico PHP 2
K Help cancellare manualmente plugin WordPress 2
A cancellare TUTTI i cookies PHP 2
S aiuto non so cancellare i dati: PHP 1
D Cancellare una Stringa di testo da un file txt PHP 8
M cancellare una immagine dal database PHP 3
F 2 Div uniti, cancellare bordo. HTML e CSS 1
ivarello Cancellare parole dopo ";" PHP 4
M cancellare del testo in sql PHP 1
C cancellare un elemento in un array memorizzato in una sessione PHP 12
F Devo cancellare un sito web su Google SEO e Posizionamento 2
D Non riesco a cancellare un href >.< Javascript 6
IImanuII Cancellare una cartella piena PHP 14
valient13 aprire un alert per cancellare Javascript 1
D Come cancellare Internet Explorer 8? Windows e Software 2
M Cancellare tutti i caratteri fra due caratteri PHP 6
L Come faccio a cancellare un account di posta su Apple Mail? Posta Elettronica 1
Web Designer Come cancellare file bloccati sul desktop Windows e Software 0
L Cancellare cookie / cache / cronologia da Safari di iPhone Smartphone e tablet 1
novello88 Cancellare un elemento con JQuery jQuery 1
novello88 [MySQL] Delete Record (cancellare una riga) MySQL 1

Discussioni simili