Author Topic: PHP Page, delete from dropdown list?  (Read 862 times)

0 Members and 1 Guest are viewing this topic.

Offline buzzkipTopic starter

  • Irregular
  • Posts: 4
    • View Profile
PHP Page, delete from dropdown list?
« on: September 02, 2010, 08:24:49 AM »
Hi all,

Please could someone guide me as to how I would create a simple php page, that has a dropdown list populated by a database table - and then a submit button.

When I select an option in the dropdown list and then click submit, it deletes the row from the database table.


Would be very much appreciative of some help  :confused:

Offline laanes

  • Enthusiast
  • Posts: 70
    • View Profile
Re: PHP Page, delete from dropdown list?
« Reply #1 on: September 02, 2010, 09:19:47 AM »
Hi all,

Please could someone guide me as to how I would create a simple php page, that has a dropdown list populated by a database table - and then a submit button.

When I select an option in the dropdown list and then click submit, it deletes the row from the database table.


Would be very much appreciative of some help  :confused:

Post your code here for people to look at so they can help you.

Offline buzzkipTopic starter

  • Irregular
  • Posts: 4
    • View Profile
Re: PHP Page, delete from dropdown list?
« Reply #2 on: September 02, 2010, 09:29:23 AM »
table: inplace
columns: field, value, stock

The drop down displays the value columns perfectly, but when I hit the submit button... nothing happens.

<?php
//create_topic.php
include 'connect.php';
include 
'header.php';

echo 
'<h2>Delete an item in the database</h2>';
if(
$_SESSION['signed_in'] == false)
{
	
echo 
'Sorry, you have to be signed in.';
}
else
{
	
if(
$_SERVER['REQUEST_METHOD'] != 'POST')
	
{
	
	
$sql "SELECT
	
	
	
	
	
field,
	
	
	
	
	
value,
	
	
	
	
	
stock
	
	
	
	
FROM
	
	
	
	
	
inplace"
;
	
	

	
	
$result mysql_query($sql);
	
	

	
	
if(!
$result)
	
	
{
	
	
	
echo 
'Error while selecting from database. Please try again later.';
	
	
}
	
	
else
	
	
{
	
	
	
if(
mysql_num_rows($result) == 0)
	
	
	
{
	
	
	
	
if(
$_SESSION['user_level'] == 1)
	
	
	
	
{
	
	
	
	
	
echo 
'You have not created any items yet.';
	
	
	
	
}
	
	
	
	
else
	
	
	
	
{
	
	
	
	
	
echo 
'Before you can post an item, you must wait for an admin to create some locations.';
	
	
	
	
}
	
	
	
}
	
	
	
else
	
	
	
{
	
	
	
	
echo 
'<form method="post" action="">
	
	
	
	
	
Item:
	
	
	
	
<select name="field">'
;
	
	
	
	
	
while(
$row mysql_fetch_assoc($result))
	
	
	
	
	
{
	
	
	
	
	
	
echo 
'<option value="' $row['field'] . '">' $row['value'] . '</option>';
	
	
	
	
	
}
	
	
	
	
echo 
'</select><input type="submit" value="Delete item" /></form>';
	
	
	
}
	
	
}
	
}
	
else
	
{
	
	
$query  "BEGIN WORK;";
	
	
$result mysql_query($query);
	
	

	
	
if(!
$result)
	
	
{
	
	
	
echo 
'An error occured while deleting your item. Please try again later.';
	
	
}
	
	
else
	
	
{
	
	
	
	
$sql "DELETE FROM inplace WHERE value = ' " $_POST['value'] . " ' ";
	
	
	
	
	
 
	
	
	
$result mysql_query($sql);
	
	
	
if(!
$result)
	
	
	
{
	
	
	
	
echo 
'An error occured while deleting your data. Please try again later.<br /><br />' mysql_error();
	
	
	
	
$sql "ROLLBACK;";
	
	
	
	
$result mysql_query($sql);
	
	
	
}
	
	
	
else
	
	
	
{
	
	
	
	
$topicid mysql_insert_id();
	
	
	
	

	
	
	
	
$sql "DELETE FROM inplace WHERE value = ' " $_POST['value'] . " ' ";


	
	
	
	
	
	

	
	
	
	
$result mysql_query($sql);
	
	
	
	

	
	
	
	
if(!
$result)
	
	
	
	
{
	
	
	
	
	
echo 
'An error occured while deleting your item. Please try again later.<br /><br />' mysql_error();
	
	
	
	
	
$sql "ROLLBACK;";
	
	
	
	
	
$result mysql_query($sql);
	
	
	
	
}
	
	
	
	
else
	
	
	
	
{
	
	
	
	
	
$sql "COMMIT;";
	
	
	
	
	
$result mysql_query($sql);

	
	
	
	
	
echo 
'You have succesfully deleted your new item.';
	
	
	
	
}
	
	
	
}
	
	
}
	
}
}

include 
'footer.php';
?>


Offline fenway

  • MySQL Si-Fu / PHP Resident Alien
  • Global Moderator
  • 'Mind Boggling!'
  • *
  • Posts: 15,443
  • Gender: Male
    • View Profile
Re: PHP Page, delete from dropdown list?
« Reply #3 on: September 06, 2010, 08:03:49 PM »
I'm sure something happens -- if you get a blank page, that's something else.

Define "nothing".
:anim_rules: Seriously... if people don't start reading this before posting, I'm going to consider not answering at all.