hi i was wondering how should i tackle this problem as i got stuck on the delete feature, getting data is fine deteling is the problem since now i made the following:

<?php
include 'cms/core/config.php';
include 'cms/core/opendb.php';

// get data
$query = "SELECT id, name FROM ody_admin.templates ORDER BY id";
$result = mysql_query($query) or die('Error : ' . mysql_error());
exit;

// remove data and skin file from server
$query = "DELETE FROM ody_admin.templates WHERE name='$name'";
$result = mysql_query($query) or die('Error : ' . mysql_error());
exit;

include 'cms/core/closedb.php';
?>
<form name="" method="post" action="<?php echo $PHP_SELF;?>">
<select name="skin" id="skin">
<?php while($row=mysql_fetch_array($result)) { ?>
<option value="<?php echo $row['name']; ?>"><?php echo $row['name']; ?></option>
<?php } ?>
</select>
<input type="submit" name="delete" id="delete" value="Delete Skin" />
</form>

thanks alot in advance guys!

Member Avatar for diafol

I'm a little confused by your snippit. If you send a form to the current page (not recommended, since 'refresh' will try to resend the form), the $name variable needs to hold data - you need to do something like:

if(isset($_POST['name'])){
  $name = $_POST['name'];
  ... do your delete query ...
}

If your skins table has an integer ID field/autonumber primary key, use this instead of the 'name' field for the option tag value attribute.

Then use that value to delete a record from the DB. If your skins have symbols/escaped characters, you may find mismatches in your WHERE clause.

Otherwise properly escape your string data.

As ardav says, use id not name , plus you might like to reverse the order of the two sql blocks such that the menu can be rebuilt with row deleted, and displayed back to you with a confirmatory message.

Something like this maybe (not tested):

<?php
include 'cms/core/config.php';
include 'cms/core/opendb.php';

$delete = isset($_POST['delete']) ? true : false;
$skinID = isset($_POST['skin']) ? intval($_POST['skin']) : null;

// remove data and skin file from server
if($delete && $skinID != null){
	$query = "DELETE FROM ody_admin.templates WHERE id='$skinID'";
	$result = mysql_query($query) or die('Error : ' . mysql_error());
	$msg = 'Skin successfully deleted';
}
else{
	$msg = '';
}

// get data
$query = "SELECT id, name FROM ody_admin.templates ORDER BY id";
$result = mysql_query($query) or die('Error : ' . mysql_error());

include 'cms/core/closedb.php';

<p><?php echo $msg ?></p>

<form name="" method="post" action="<?php echo $PHP_SELF;?>">
<select name="skin" id="skin">
<?php while($row=mysql_fetch_array($result)) { ?>
<option value="<?php echo $row['id']; ?>"><?php echo $row['name']; ?></option>
<?php } ?>
</select>
<input type="submit" name="delete" id="delete" value="Delete Skin" />
</form>

And don't forget that you may also need to perform further deletions from your database (or other housekeeping) such that you are not left with any hanging records (ones that have the deleted skin id as a foreign key).

Airshow

cheers guys, you are great

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.