Jump to content

Recommended Posts

Hi


I have a simple database which lists colours and displays them as background colours in a table.

I also have a form on the page to insert new colours and another to delete a colour from the database.

The delete form is not passing the correct strings to delete.php.



The database is called test and it has fields id and colour.


Here is the form

[code]<h3>Delete colour</h3>
<form action="delete.php" method="get" id="submit">
<select name='Colours'>
<?php

$result = mysql_query($query) or die ("Couldn't execute query.");


// Populate cells using a mysql_fetch_array script
while ($row=mysql_fetch_array($result))
{

    $id=$row["id"];
    $colour=$row["colour"];
    



//Populates a drop down menu

echo "<option value='$id'id='$id'>$id $colour</option>";



}


?>

</select>

<input type="submit" name="submit" value="submit"><br>

</form>




[/code]





and here is the delete script in delete.php



[code]


<?php


include('admin/dbconnection.php');



$delete=$_GET['submit'];
$id=$_GET['id'];
//$colour=$_GET['colour'];

echo"$id";

$delete=mysql_query("DELETE FROM boxes WHERE id=$id");

    
    
    
?>






[/code]
Link to comment
https://forums.phpfreaks.com/topic/5755-delete-script-not-passing-variable/
Share on other sites

[!--quoteo(post=358171:date=Mar 25 2006, 02:53 AM:name=rahish)--][div class=\'quotetop\']QUOTE(rahish @ Mar 25 2006, 02:53 AM) [snapback]358171[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Hi
I have a simple database which lists colours and displays them as background colours in a table.

I also have a form on the page to insert new colours and another to delete a colour from the database.

The delete form is not passing the correct strings to delete.php.
The database is called test and it has fields id and colour.
Here is the form

[code]<h3>Delete colour</h3>
<form action="delete.php" method="get" id="submit">
<select name='Colours'>
<?php

$result = mysql_query($query) or die ("Couldn't execute query.");
// Populate cells using a mysql_fetch_array script
while ($row=mysql_fetch_array($result))
{

    $id=$row["id"];
    $colour=$row["colour"];
    
//Populates a drop down menu

echo "<option value='$id'id='$id'>$id $colour</option>";
}
?>

</select>

<input type="submit" name="submit" value="submit"><br>

</form>
[/code]
and here is the delete script in delete.php
[code]
<?php
include('admin/dbconnection.php');
$delete=$_GET['submit'];
$id=$_GET['id'];
//$colour=$_GET['colour'];

echo"$id";

$delete=mysql_query("DELETE FROM boxes WHERE id=$id");

    
    
    
?>
[/code]
[/quote]



I think its something to do with the way that you have printed your select box, try the following

$result=mysql_query($query);


print "<select name='YOURNAME' size=1>\n";

while ($row=mysql_fetch_row($result))

{


print "<option value='$row[0]'>$row[0]\n";

}




notes : Can be assigned to anything and will be the variable you collect on the next page !

$id = $_GET['YOURNAME'];


Would hold your value



Also for the drop down to display the colour dont change the option value but the second one like

print "<option value='$row[0]'>$colour\n";



That should work !!

Nirmal
Thanks for your help.

I actually got it to work this way

I changed the id on the form to colour


[code]<h3>Delete colour</h3>
<form action="delete.php" method="get" id="colour">





<?php

$result=mysql_query($query);


echo "<select name='colour' size=1>\n";

while ($row=mysql_fetch_array($result))

{

    $id=$row["id"];
    $colour=$row["colour"];

echo "<option value='$id'>$colour\n";




}
echo "</select>";

echo "<input type='submit' name='submit' value='submit'>";



?>



<br>

</form>[/code]


and delete.php to this



[code]<?php


include('admin/dbconnection.php');



$delete=$_GET['submit'];
$colour=$_GET['colour'];

echo"$colour";

$delete=mysql_query("DELETE FROM boxes WHERE id=$colour");

    
    
    
?>[/code]


Not quite sure why it worked but it deletes colours.


Thanks again

Rahish





[!--quoteo(post=358233:date=Mar 25 2006, 10:48 AM:name=norman100)--][div class=\'quotetop\']QUOTE(norman100 @ Mar 25 2006, 10:48 AM) [snapback]358233[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I think its something to do with the way that you have printed your select box, try the following

$result=mysql_query($query);
print "<select name='YOURNAME' size=1>\n";

while ($row=mysql_fetch_row($result))

{


print "<option value='$row[0]'>$row[0]\n";

}
notes : Can be assigned to anything and will be the variable you collect on the next page !

$id = $_GET['YOURNAME'];
Would hold your value
Also for the drop down to display the colour dont change the option value but the second one like

print "<option value='$row[0]'>$colour\n";
That should work !!

Nirmal
[/quote]
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.