Jump to content
php.lv forumi

delete


ziedinjsh

Recommended Posts

Man tāds jautājums.. ka es varu izdzēst informāciju no mysql?

 

Šini gadījumā man ir links kuram ir jāizdzēš lietotāja avatars

 

<a href='delete.php?avatar=delete&avatar=".$row['avatar']."' >

 

delete.php

$row = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE email = '{$_SESSION['email']}'"));

if($_GET["avatar"]=="delete")
{


$avatar = $row['avatar'];
   $sql = sprintf("DELETE FROM users WHERE avatar = $avatar");
   $result = mysql_query($sql);


}else{
header("location: edit_profile.php");
}

 

kapēc viņš neizdzēš??

Edited by ziedinjsh
Link to comment
Share on other sites

Kādā jēgā tu tur izmanto sprintf? Tu zini ko tā funkcija vispār dara?

 

Lai nu kā - galvenā vaina ir tur, ka DELETE kvērijā tev avatar lauka vērtība nav pēdiņās. (ja vien tas nav int)

 

Pēcāk gan es jau paredzu jautājumu - kādēļ tas man izdzēš visu lietotāju, bet par to jau vēlāk. ^_^

Link to comment
Share on other sites

nu man tagad ir šādi:

<a href='delete.php?wath=avatar' >

 

delete.php

session_start();
include "misc/db.php";
$row = mysql_fetch_array(mysql_query("SELECT * FROM users WHERE email = '{$_SESSION['email']}'"));

if($_GET["wath"]=="avatar")
{
$id = $row['user_id'];
   mysql_query("UPDATE users SET avatar = '' WHERE id = '".$id."'");



}else{
header("location: edit_profile.php");
}

uzspiežot uz linka atveras tukšā lapa un viss.. un bildi viņš neizdzēš!

Link to comment
Share on other sites

ā, es sapratu kļūdu... WHERE id = '".$id."' vajadzēja WHERE user_id '".$id."'

 

un kā es varētu unlink(); izmantot lai man izdzēš bildi no foldera?

 

$avatar = $row['avatar']
$user_id = $row['user_id']
mysql_query("UPDATE users SET avatar = '' WHERE user_id = '".$user_id."'");
unlink("avatars/".$avatar);
header("location: edit_profile.php");

Edited by ziedinjsh
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...