DELETE FROM table lukt ff niet

Gestart doorKenzo8 reacties11 weergaven

9 berichten · pagina 1 van 1

Kenzo

Lid · Topicstarter

Berichten
1.314
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
heey iedereen,

ben ik weer.
nu wil ik een heel product verwijderen als ik het id van het product(web_id) via een $_POST verstuur.
dus niet alleen het web_id verwijderen maar ook: web_product, web_text, web_price en web_picture van 1product dus niet alle producten.
hoop dat iemand kan helpen. eventueel tegen een vergoedingsmile
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <title>Formuliertje</title>
</head>
<body>
<form action="" method="post">
<input name="web_id" type="text"></p>
<p><input name="Submit" type="submit" value="verwijder"></p>
</form>
</body>
</html>
[COLOR= #0000BB]<?php

$dbhost[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]localhost[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$dbuser[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]*****[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$dbpass[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]*****[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$conn[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_connect"]mysql_connect[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$dbhost[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$dbuser[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$dbpass[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700](![/COLOR] [COLOR= #0000BB]$conn[/COLOR] [COLOR= #007700])
{[/COLOR]
  [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]Could not connect: [/COLOR] [COLOR= #007700].[/COLOR] [URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());
}[/COLOR]
[COLOR= #0000BB]$sql[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]DELETE FROM products
        WHERE web_id= [/COLOR] [COLOR= #007700].[/COLOR] htmlspecialchars[COLOR= #007700]([/COLOR][COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]web_id[/COLOR][COLOR= #007700]]) .[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700];[/COLOR]

[URL="http://www.php.net/mysql_select_db"]mysql_select_db[/URL][COLOR= #007700](*****);[/COLOR]
[COLOR= #0000BB]$retval[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR] [COLOR= #0000BB]$sql[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$conn[/COLOR] [COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700](![/COLOR] [COLOR= #0000BB]$retval[/COLOR] [COLOR= #007700])
{[/COLOR]
  [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]Could not delete data: [/COLOR] [COLOR= #007700].[/COLOR] [URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());
}[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"data is verwijderd
"[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/mysql_close"]mysql_close[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$conn[/COLOR][COLOR= #007700]);[/COLOR]

?>
0
Berichten
3.461
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
(r.23)

$sql = DELETE FROM products
        WHERE web_id=  . htmlspecialchars($row[web_id]) . ;


Veranderen in

$sql = DELETE FROM products
        WHERE web_id=  . $row[web_id]) . ;


Ik denk dat het zo wel moet werken. wink
0
Berichten
5.795
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
je haalt de ids niet eens op uit de tabel en $row bestaat dus niet en je moet dus eerst uit tabel halen
0
Berichten
3.283
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Wat wil je maken? Dat als je formulier post dat hij dan het opgegeven id verwijderd? Zoja dan moet je $_POST gebruiken.
0
Kenzo

Lid · Topicstarter

Berichten
1.314
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ja maar dat zei ik al marijn,
ik wil dus dat ik een product wat bestaat uit: web_id, web_product, web_text, web_price en web_picture dus dat moet allemaal in 1 keer weg dus een heel product weghalen maar hoe?
Ik hoop dat jullie het snappen wilner best een vergoeding voor gevensmile
0
Berichten
5.957
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Zoals hij zegt moet je $_POST[web_id] gebruiken i.p.v. htmlspecialchars($row[web_id]
0
Berichten
6.356
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
<html>
<head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    <title>Formuliertje</title>
</head>
<body>
<form action="" method="post">
<input name="web_id" type="text"></p>
<p><input name="Submit" type="submit" value="verwijder"></p>
</form>
</body>
</html>
[COLOR= #0000BB]<?php

$dbhost[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]localhost[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$dbuser[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]*****[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$dbpass[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]*****[/COLOR][COLOR= #007700];[/COLOR]
[COLOR= #0000BB]$conn[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_connect"]mysql_connect[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$dbhost[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$dbuser[/COLOR][COLOR= #007700],[/COLOR] [COLOR= #0000BB]$dbpass[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700](![/COLOR] [COLOR= #0000BB]$conn[/COLOR] [COLOR= #007700])
{[/COLOR]
  [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]Could not connect: [/COLOR] [COLOR= #007700].[/COLOR] [URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());
}[/COLOR]
[COLOR= #0000BB]$sql[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]DELETE * FROM products
        WHERE web_id= [/COLOR][COLOR= #0000BB]$_POST[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]web_id[/COLOR][COLOR= #007700]][/COLOR][COLOR= #DD0000];

mysql_select_db(*****);
$retval = mysql_query( $sql, $conn );
if(! $retval )
{
  die([/COLOR]Could not delete data[COLOR= #007700]:[/COLOR]  [COLOR= #007700].[/COLOR] [URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());
}[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]"data is verwijderdn"[/COLOR][COLOR= #007700];[/COLOR]
[URL="http://www.php.net/mysql_close"]mysql_close[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$conn[/COLOR][COLOR= #007700]);[/COLOR]

?>
0
Kenzo

Lid · Topicstarter

Berichten
1.314
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
mikeb die gaat zoiezo niet werkenyummiemaar ik heb hem nu opgelost.
bedankt marijn
0
Berichten
1.641
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Als je vragen over delete enzo hebt kan je toch ook terecht op w3schools.com. Daar heb ik veel van geleerd
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren