Jump to content

Delete form


MDanz

Recommended Posts

<form action='delete.php' method='post'>
   <select> 
<?php
$sql='SELECT name FROM castack';
$result =mysql_query($sql);
while ($data=mysql_fetch_assoc($result)){

echo $data['name']; 
} 
?>
</select>
     <input type='submit' name='delete' value='Delete' />
   </form>

 

i have a list/menu and they are supposed to display the all the results in the database.  I select what one and i press the delete button.    this isn't working its not displaying whats in the database. 

Link to comment
https://forums.phpfreaks.com/topic/171732-delete-form/
Share on other sites

sry i'll be clearer

 

a drop down list with my results.  And a delete button.

 

this is what i attempted. But i'm not getting my results in the drop down list.

 

 <form action='added.php' method='post'>
   <select> 
<?php
$sql='SELECT name FROM castack';
$result =mysql_query($sql);
while ($data=mysql_fetch_assoc($result)){

$delete=$data['name'];
echo "$delete"; 
} 
?>
</select>
     <input type='submit' name='delete' value='Delete' />
   </form>

 

 

i'm quite new to php but i'm getting the hang of it

Link to comment
https://forums.phpfreaks.com/topic/171732-delete-form/#findComment-905539
Share on other sites

$sql='SELECT FROM ...';

 

Should be:

$sql=mysql_query("SELECT FROM...."); 

 

 

Also, you're not connecting to a database. You need to connect to a database to delete things from a table.

 

AND, you should not do this:

echo "$delete"; 

 

it should be

 

echo $delete; 

 

You might want to go over to W3C Tutorials or Tizag or something you look a little discombobulated with PHP.

Link to comment
https://forums.phpfreaks.com/topic/171732-delete-form/#findComment-905541
Share on other sites

k i changed some stuff

 

still not getting the results from database in drop down list..

 

<form action='added.php' method='post'>
   <select> 
<?php
mysql_connect("localhost", "Master", "password");
mysql_select_db("db");
$sql=mysql_query("SELECT name FROM castack");
$result =mysql_query($sql);
while ($data=mysql_fetch_assoc($result)){

$delete=$data['name'];
echo $delete; 
} 
?>
</select>
     <input type='submit' name='delete' value='Delete' />
   </form>

Link to comment
https://forums.phpfreaks.com/topic/171732-delete-form/#findComment-905545
Share on other sites

You may want to include the <select> fields in the PHP code since you want a new select field for every name.

<form action='added.php' method='post'>
  
<?php
mysql_connect("localhost", "Master", "password");
mysql_select_db("db");
$sql=mysql_query("SELECT name FROM castack");
$result =mysql_query($sql);
while ($data=mysql_fetch_assoc($result)){

$delete=$data['name'];
echo " <select>"; 
echo $delete; 
echo "</select>"; 
} 
?>


Will give you a box that will have an option for each name. 
     <input type='submit' name='delete' value='Delete' />
   </form>

Link to comment
https://forums.phpfreaks.com/topic/171732-delete-form/#findComment-905552
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.