Delete id
skillat - 25/10/2005 16:33
Onbekend
De bedoeling is dat als je op het plaatje del.png drukt dat het id dan gewist word.
Ik ben gisteren begonnen met php/mysql en snap er dus nog amper wat van .. hoop dat iemand me een beetje opweg wil helpen.
Voorbeeld voor het idee:
http://www.sneldesign.com/phpshit/admin.php
Code:
<?php
include 'config.php';
?>
<!doctype html public "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title><?php echo "$titel"; ?></title>
<meta http-equiv="title" content="<?php echo "$metatitel"; ?>" />
<meta http-equiv="description" content="<?php echo "$metadescription"; ?>" />
<meta http-equiv="keywords" content="<?php echo "$metakeywords"; ?>" />
<meta http-equiv="generator" content="<?php echo "$metagenerator"; ?>" />
</head>
<body>
<table border="1" width="50%" cellspacing="0" cellpadding="0" bgcolor="#808080">
<tr>
<td width="25%" align="center">Enemy</td>
<td width="20%" align="center">Score</td>
<td width="20%" align="center">Match Type</td>
<td width="25%" align="center">Competition</td>
<td width="10%" align="center">Delete</td>
</tr>
</table>
<?php
$res = mysql_query("SELECT enemy,score,matchtype,competition FROM wars");
while ($obj = mysql_fetch_object($res)) {
?>
<table border="1" width="50%" cellspacing="0" cellpadding="0" bgcolor="#808080">
<tr>
<td width="25%" bgcolor="#C0C0C0"><?php echo $obj->enemy.""; ?></td>
<td width="20%" bgcolor="#C0C0C0"><?php echo $obj->score.""; ?></td>
<td width="20%" bgcolor="#C0C0C0"><?php echo $obj->matchtype.""; ?></td>
<td width="25%" bgcolor="#C0C0C0"><?php echo $obj->competition.""; ?></td>
<td width="10%" bgcolor="#C0C0C0">
<? // als je dan op del.png klikt zou het id gedelete moeten worden.. maar hoe ? ?>
<a href=$PHP_SELF?deleteid=??><img src="del.png" border="0" alt="Delete Bericht"></a>
</td>
</tr>
</table>
<?php
// while afsluiten
}
mysql_free_result($res);
?>
</body>
</html>
<?php
include 'config.php' ;
?>
<!doctype html public "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>
<?php echo "$titel " ; ?> </title>
<meta http-equiv="title" content="
<?php echo "$metatitel " ; ?> " />
<meta http-equiv="description" content="
<?php echo "$metadescription " ; ?> " />
<meta http-equiv="keywords" content="
<?php echo "$metakeywords " ; ?> " />
<meta http-equiv="generator" content="
<?php echo "$metagenerator " ; ?> " />
</head>
<body>
<table border="1" width="50%" cellspacing="0" cellpadding="0" bgcolor="#808080">
<tr>
<td width="25%" align="center">Enemy</td>
<td width="20%" align="center">Score</td>
<td width="20%" align="center">Match Type</td>
<td width="25%" align="center">Competition</td>
<td width="10%" align="center">Delete</td>
</tr>
</table>
<?php
$res = mysql_query ( "SELECT enemy,score,matchtype,competition FROM wars" ) ;
?>
<table border="1" width="50%" cellspacing="0" cellpadding="0" bgcolor="#808080">
<tr>
<td width="25%" bgcolor="#C0C0C0">
<?php echo $obj -> enemy . "" ; ?> </td>
<td width="20%" bgcolor="#C0C0C0">
<?php echo $obj -> score . "" ; ?> </td>
<td width="20%" bgcolor="#C0C0C0">
<?php echo $obj -> matchtype . "" ; ?> </td>
<td width="25%" bgcolor="#C0C0C0">
<?php echo $obj -> competition . "" ; ?> </td>
<td width="10%" bgcolor="#C0C0C0">
<? // als je dan op del.png klikt zou het id gedelete moeten worden.. maar hoe ? ?>
<a href=$PHP_SELF?deleteid=??><img src="del.png" border="0" alt="Delete Bericht"></a>
</td>
</tr>
</table>
<?php
// while afsluiten
}
?>
</body>
</html>
De tabel maakt automatisch een id aan.
CREATE TABLE `wars` (
pid INT(10) AUTO_INCREMENT,
enemy VARCHAR(50) NOT NULL,
score VARCHAR(10) NOT NULL,
matchtype VARCHAR(10) NOT NULL,
competition VARCHAR(20) NOT NULL,
PRIMARY KEY (pid)
) TYPE=MyISAM;
CREATE TABLE `wars` (
pid INT( 10 ) AUTO_INCREMENT,
enemy VARCHAR( 50 ) NOT NULL ,
score VARCHAR( 10 ) NOT NULL ,
matchtype VARCHAR( 10 ) NOT NULL ,
competition VARCHAR( 20 ) NOT NULL ,
) TYPE= MyISAM;
6 antwoorden
Gesponsorde links
Rens - 25/10/2005 16:36
Crew algemeen
Bij regel 31 voeg je pid toe:
$res = mysql_query("SELECT pid, enemy,score,matchtype,competition FROM wars");
$res = mysql_query ( "SELECT pid, enemy,score,matchtype,competition FROM wars" ) ;
En dan kan je in je while loop zo doen:
of:
Dus word regel 44:
<a href="<?=$SERVER['PHP_SELF'];?>?deleteid=<?=$obj->pid;?>"><img src="del.png" border="0" alt="Delete Bericht"></a>
<a href="<?= $SERVER [ 'PHP_SELF' ] ; ?> ?deleteid=<?= $obj -> pid ; ?> "><img src="del.png" border="0" alt="Delete Bericht"></a>
Opmerking:
Gebruik superglobals zoals $_SERVER, $_GET, $_POST e.d.
En dit:
<?php echo $obj->enemy.""; ?>
<?php echo $obj -> enemy . "" ; ?>
mag ook zo:
<?="blaat";?> is een verkorte PHP echo statement.
nemesiskoen - 25/10/2005 16:38 (laatste wijziging 25/10/2005 17:25)
PHP expert
<a href="<?= $_SERVER['PHP_SELF'] ?>?deleteid=<?= $obj->id ?>"><img src="del.png" border="0" alt="Delete Bericht" /></a>
<a href="<?= $_SERVER [ 'PHP_SELF' ] ?> ?deleteid=<?= $obj -> id ?> "><img src="del.png" border="0" alt="Delete Bericht" /></a>
En onderaan zet je
<?php
if(isSet($_GET['deleteid']) && is_numeric($_GET['deleteid'])) {
MySQL_query("DELETE FROM wars WHERE id = '". $_GET['deleteid'] ."'");
?>
<?php
MySQL_query ( "DELETE FROM wars WHERE id = '" . $_GET [ 'deleteid' ] . "'" ) ; ?>
Nu moet je wel op passen dat er niemand aan je vraagt om naar http://www.jouwsite.com/admin.php?deleteid=2 ofzo te gaan. Want dan delete je het bericht.
skillat - 25/10/2005 16:51 (laatste wijziging 25/10/2005 17:12)
Onbekend
Hij delete nog niks..
<?php
include 'config.php';
?>
<!doctype html public "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title><?php echo "$titel"; ?></title>
<meta http-equiv="title" content="<?php echo "$metatitel"; ?>" />
<meta http-equiv="description" content="<?php echo "$metadescription"; ?>" />
<meta http-equiv="keywords" content="<?php echo "$metakeywords"; ?>" />
<meta http-equiv="generator" content="<?php echo "$metagenerator"; ?>" />
</head>
<body>
<table border="1" width="50%" cellspacing="0" cellpadding="0" bgcolor="#808080">
<tr>
<td width="25%" align="center">Enemy</td>
<td width="20%" align="center">Score</td>
<td width="20%" align="center">Match Type</td>
<td width="25%" align="center">Competition</td>
<td width="10%" align="center">Delete</td>
</tr>
</table>
<?php
$res = mysql_query("SELECT pid, enemy,score,matchtype,competition FROM wars");
while ($obj = mysql_fetch_object($res)) {
?>
<table border="1" width="50%" cellspacing="0" cellpadding="0" bgcolor="#808080">
<tr>
<td width="25%" bgcolor="#C0C0C0"><?php echo $obj->enemy.""; ?></td>
<td width="20%" bgcolor="#C0C0C0"><?php echo $obj->score.""; ?></td>
<td width="20%" bgcolor="#C0C0C0"><?php echo $obj->matchtype.""; ?></td>
<td width="25%" bgcolor="#C0C0C0"><?php echo $obj->competition.""; ?></td>
<td width="10%" bgcolor="#C0C0C0"><a href="<?= $_SERVER['PHP_SELF'] ?>?deleteid=<?= $obj->pid ?>"><img src="del.png" border="0" alt="Delete Bericht" /></a></td>
</tr>
</table>
<?php
// while afsluiten
}
mysql_free_result($res);
?>
<?php
if(isSet($_GET['deleteid']) && is_numeric($_GET['deleteid'])) {
MySQL_query("DELETE * FROM wars WHERE pid = '". $_GET['deleteid'] ."'");
}
?>
</body>
</html>
<?php
include 'config.php' ;
?>
<!doctype html public "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>
<?php echo "$titel " ; ?> </title>
<meta http-equiv="title" content="
<?php echo "$metatitel " ; ?> " />
<meta http-equiv="description" content="
<?php echo "$metadescription " ; ?> " />
<meta http-equiv="keywords" content="
<?php echo "$metakeywords " ; ?> " />
<meta http-equiv="generator" content="
<?php echo "$metagenerator " ; ?> " />
</head>
<body>
<table border="1" width="50%" cellspacing="0" cellpadding="0" bgcolor="#808080">
<tr>
<td width="25%" align="center">Enemy</td>
<td width="20%" align="center">Score</td>
<td width="20%" align="center">Match Type</td>
<td width="25%" align="center">Competition</td>
<td width="10%" align="center">Delete</td>
</tr>
</table>
<?php
$res = mysql_query ( "SELECT pid, enemy,score,matchtype,competition FROM wars" ) ;
?>
<table border="1" width="50%" cellspacing="0" cellpadding="0" bgcolor="#808080">
<tr>
<td width="25%" bgcolor="#C0C0C0">
<?php echo $obj -> enemy . "" ; ?> </td>
<td width="20%" bgcolor="#C0C0C0">
<?php echo $obj -> score . "" ; ?> </td>
<td width="20%" bgcolor="#C0C0C0">
<?php echo $obj -> matchtype . "" ; ?> </td>
<td width="25%" bgcolor="#C0C0C0">
<?php echo $obj -> competition . "" ; ?> </td>
<td width="10%" bgcolor="#C0C0C0"><a href="<?= $_SERVER [ 'PHP_SELF' ] ?> ?deleteid=<?= $obj -> pid ?> "><img src="del.png" border="0" alt="Delete Bericht" /></a></td>
</tr>
</table>
<?php
// while afsluiten
}
?>
<?php
MySQL_query ( "DELETE * FROM wars WHERE pid = '" . $_GET [ 'deleteid' ] . "'" ) ; }
?>
</body>
</html>
Ibrahim - 25/10/2005 17:24 (laatste wijziging 25/10/2005 17:38)
PHP expert
haal die * weg
MySQL_query("DELETE * FROM wars WHERE pid = '". $_GET['deleteid'] ."'");
edit:
<?php
include 'config.php';
?>
<!doctype html public "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title><?php echo $titel; ?></title>
<meta http-equiv="title" content="<?=$metatitel?>" />
<meta http-equiv="description" content="<?=$metadescription?>" />
<meta http-equiv="keywords" content="<?=$metakeywords?>" />
<meta http-equiv="generator" content="<?=$metagenerator ?>" />
</head>
<body>
<table border="1" width="50%" cellspacing="0" cellpadding="0" bgcolor="#808080">
<tr>
<td width="25%" align="center">Enemy</td>
<td width="20%" align="center">Score</td>
<td width="20%" align="center">Match Type</td>
<td width="25%" align="center">Competition</td>
<td width="10%" align="center">Delete</td>
</tr>
</table>
<?php
$res = mysql_query("SELECT pid, enemy,score,matchtype,competition FROM wars");
while ($obj = mysql_fetch_object($res)) {
?>
<table border="1" width="50%" cellspacing="0" cellpadding="0" bgcolor="#808080">
<tr>
<td width="25%" bgcolor="#C0C0C0"><?=$obj->enemy ?></td>
<td width="20%" bgcolor="#C0C0C0"><?=$obj->score?></td>
<td width="20%" bgcolor="#C0C0C0"><?=$obj->matchtype?></td>
<td width="25%" bgcolor="#C0C0C0"><?=$obj->competition?></td>
<td width="10%" bgcolor="#C0C0C0"><a href="<?= $_SERVER['PHP_SELF'] ?>?deleteid=<?= $obj->pid ?>"><img src="del.png" border="0" alt="Delete Bericht" /></a></td>
</tr>
</table>
<?php
// while afsluiten
}
mysql_free_result($res);
?>
<?php
if(isSet($_GET['deleteid']) && is_numeric($_GET['deleteid'])) {
MySQL_query("DELETE FROM wars WHERE pid = '". $_GET['deleteid'] ."'");
}
?>
</body>
</html>
<?php
include 'config.php' ;
?>
<!doctype html public "-//W3C//DTD HTML 4.01//EN">
<html>
<head>
<title>
<?php echo $titel ; ?> </title>
<meta http-equiv="title" content="<?= $metatitel ?> " />
<meta http-equiv="description" content="<?= $metadescription ?> " />
<meta http-equiv="keywords" content="<?= $metakeywords ?> " />
<meta http-equiv="generator" content="<?= $metagenerator ?> " />
</head>
<body>
<table border="1" width="50%" cellspacing="0" cellpadding="0" bgcolor="#808080">
<tr>
<td width="25%" align="center">Enemy</td>
<td width="20%" align="center">Score</td>
<td width="20%" align="center">Match Type</td>
<td width="25%" align="center">Competition</td>
<td width="10%" align="center">Delete</td>
</tr>
</table>
<?php
$res = mysql_query ( "SELECT pid, enemy,score,matchtype,competition FROM wars" ) ;
?>
<table border="1" width="50%" cellspacing="0" cellpadding="0" bgcolor="#808080">
<tr>
<td width="25%" bgcolor="#C0C0C0"><?= $obj -> enemy ?> </td>
<td width="20%" bgcolor="#C0C0C0"><?= $obj -> score ?> </td>
<td width="20%" bgcolor="#C0C0C0"><?= $obj -> matchtype ?> </td>
<td width="25%" bgcolor="#C0C0C0"><?= $obj -> competition ?> </td>
<td width="10%" bgcolor="#C0C0C0"><a href="<?= $_SERVER [ 'PHP_SELF' ] ?> ?deleteid=<?= $obj -> pid ?> "><img src="del.png" border="0" alt="Delete Bericht" /></a></td>
</tr>
</table>
<?php
// while afsluiten
}
?>
<?php
MySQL_query ( "DELETE FROM wars WHERE pid = '" . $_GET [ 'deleteid' ] . "'" ) ; }
?>
</body>
</html>
Gesponsorde links
Dit onderwerp is gesloten .