Jump to content


Photo

Delete script not passing variable


  • Please log in to reply
2 replies to this topic

#1 rahish

rahish
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 25 March 2006 - 07:53 AM

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

<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>










and here is the delete script in delete.php





<?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");

    
    
    
?>








#2 norman100

norman100
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 25 March 2006 - 03:48 PM

[!--quoteo(post=358171:date=Mar 25 2006, 02:53 AM:name=rahish)--][div class=\'quotetop\']QUOTE(rahish @ Mar 25 2006, 02:53 AM) View Post[/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

<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>

and here is the delete script in delete.php
<?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");

    
    
    
?>
[/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


#3 rahish

rahish
  • Members
  • PipPipPip
  • Advanced Member
  • 31 posts

Posted 25 March 2006 - 08:26 PM

Thanks for your help.

I actually got it to work this way

I changed the id on the form to colour


<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>



and delete.php to this



<?php


include('admin/dbconnection.php');



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

echo"$colour";

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

    
    
    
?>



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) View Post[/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]





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users