blackpower Posted May 19, 2008 at 08:05 PM Report Share #186156 Posted May 19, 2008 at 08:05 PM bem ando de volta disto e ninguém consegue ajudar eu criar um botão em que quando carregasse apagava uma linha da base de dados mas o k consegui fazer e apagar a tabela toda que mt mau. códico da parte de tabela: <head> <title>CSS Tables</title> <link href="styles.css" rel="stylesheet" type="text/css" /> </head> <body> <?php $conn = mysql_connect("localhost","root","") or die (mysql_error()); mysql_select_db("pap",$conn) or die (mysql_error()); $query = "SELECT * FROM perfil ORDER BY user"; $result = mysql_query ($query) or die (mysql_error()); ?> <table id="mytable" cellspacing="0" summary=""> <tr> <th scope="col" abbr="Nome">Nome</th> <th scope="col" abbr="Password">Password</th> <th scope="col" abbr="Admin">Admin</th> </tr> <?php while($row = mysql_fetch_assoc($result)){ echo '<tr><td>'.$row ["user"].'</td>'; echo '<td>'.$row ["pass"].'</td>'; echo '<td>'.$row ["admin"].'</td><td>'; echo '<form METHOD ACTION="connapagaruser.php"> <input type=submit value="Apagar" name=apagar>'; } mysql_free_result ($result); mysql_close($conn); ?> </table> </body> </html> codico apagar: <?php $con = mysql_connect("localhost","root",""); mysql_select_db("pap", $con); mysql_query("DELETE FROM perfil where user=='$user' "); mysql_close($con); ?> Link to comment Share on other sites More sharing options...
cyclop Posted May 19, 2008 at 08:26 PM Report Share #186165 Posted May 19, 2008 at 08:26 PM altera esse == para =, estas a fazer uma instrução de sql, não é uma comparação 🙂 "Quando eu for grande quero ser como o Celso" Link to comment Share on other sites More sharing options...
psiico Posted May 19, 2008 at 08:36 PM Report Share #186169 Posted May 19, 2008 at 08:36 PM tens q fazer 1 delete na base de dados pelo nome ou ID da tabela. ex: mysql_query("DELETE FROM users where ID='Nome da pessoa'"); Psiico // Portfolio Link to comment Share on other sites More sharing options...
infopc Posted May 19, 2008 at 11:05 PM Report Share #186216 Posted May 19, 2008 at 11:05 PM O problema está mesmo nos dois sinais de igual (==) deves usar so um, se for um campo varchar podes tambem usar LIKE EX: DELETE FROM `tabela_a_apagar` WHERE `campo_de_verificacao` LIKE 'string'; O que não tem solução, solucionado esta... Link to comment Share on other sites More sharing options...
infopc Posted May 19, 2008 at 11:23 PM Report Share #186221 Posted May 19, 2008 at 11:23 PM Já agora tenta assim <?php //ficheiro do formulario while($row = mysql_fetch_assoc($result)){ echo '<form method="post" action="connapagaruser.php"> <tr> <td><input type="hidden" name="user" value="'.$row ["user"].'" />'.$row ["user"].'</td> <td>'.$row ["pass"].'</td> <td>'.$row ["admin"].'</td> <td><input type="submit" value="apagar" /></td> </tr> </form>'; } mysql_free_result ($result); mysql_close($conn); ?> <?php //ficheiro connapagaruser.php $con = mysql_connect("localhost","root",""); mysql_select_db("pap", $con); mysql_query('DELETE FROM perfil where user=\''.$_POST['user'].'\';'); mysql_close($con); ?> O que não tem solução, solucionado esta... Link to comment Share on other sites More sharing options...
blackpower Posted May 20, 2008 at 08:20 AM Author Report Share #186239 Posted May 20, 2008 at 08:20 AM peço desculpa pelo portugues, e o seguinte como sei k nakela linha da dados quando carregar no botao para delete ele so vai mesmo apagar so mente aquela linha. Link to comment Share on other sites More sharing options...
psiico Posted May 20, 2008 at 11:55 PM Report Share #186402 Posted May 20, 2008 at 11:55 PM para apagar uma linha SÓ, em vez de utilizares LIKE utiliza = porque pode apagar outras sem intenção. Psiico // Portfolio Link to comment Share on other sites More sharing options...
naoliveira Posted May 26, 2008 at 01:35 PM Report Share #187568 Posted May 26, 2008 at 01:35 PM Se o campo for único, só apaga uma linha visto não poder haver entradas duplicadas nesse campo e aí esta instrução do psiico funciona: mysql_query('DELETE FROM perfil where user=\''.$_POST['user'].'\';'); Se puderes ter dados duplicados nesse campo acrescenta o LIMIT 1 à instrução do psiico: mysql_query('DELETE FROM perfil where user=\''.$_POST['user'].'\' LIMIT 1;'); neste caso garantes que só apagas uma linha, mas não sabes qual. Para apagares a linha que queres, tens de encontrar uma forma de fazeres um DELETE com os dados que te garantam que é mesmo aquela linha para apagar. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now