Jump to content

Recommended Posts

Hey guys and girls,

 

I'm having a problem with deleting in mysql queries.  I've never tried to use this query before so I'm probably not doing it right.  I've tried it several different ways but it's not working... no error messages, just not working.  If you can help out it would be greatly appreciated.  Thanks in advance.

 

Here's the latest thing that I've tried:

<?php
// TEST SECTION

$result = mysql_query("SELECT year,make,model,lp FROM vehicles WHERE email = '$email'");

while( $row = mysql_fetch_array( $result ) )
{

$lp = $row[ "lp" ];
echo "<p>";
echo $row[ "year" ] . " ";
echo $row[ "make" ] . " ";
echo $row[ "model" ] . "   ";
echo "<form action=\"editvehicle.php\" method=\"POST\">";
echo "<input name=\"lp\" type=\"hidden\" id=\"lp\" value=\"$lp\">";
echo "<input name=\"submit\" type=\"submit\" value=\"Edit Vehicle\">";
echo "</form>";
if (!isset($_POST['$lp'])) {

echo "<form action=\"members.php\" method=\"POST\">";
echo "<input name=\"lp\" type=\"hidden\" id=\"lp\" value=\"$lp\">";
echo "<input name=\"$lp\" type=\"submit\" value=\"Delete\">";
echo "</form>";
echo "</p>";

} else {

mysql_query("DELETE * FROM vehicles WHERE email = '$email' AND lp = '$lp'");

}
}
echo "<p><form action=\"addvehicle.php\" method=\"POST\"></p>";
echo "<input name=\"email\" type=\"hidden\" id=\"email\" value=\"$email\">";
echo "<input name=\"submit\" type=\"submit\" value=\"Add A Vehicle?\">";

// END TEST SECTION
?>

I tried that too, before I posted the thread, but I still get nothing.  Any other ideas?

 

Try to do it without the if/else statements. That way you will know if it actually makes it to the query and know for sure that that part works correctly. I'll bet it's not making it there.

I figured it out... I had to put it in 2 pages.  There is a list of vehicles in the database, the while loop lists all the vehicles attached to a specific email address.  The code that I was trying to get to work was to get the form to delete a specific vehicle if you click on the "Delete" button.  This is how I did it:

 

Page 1:

<?php

$result = mysql_query("SELECT year,make,model,lp FROM vehicles WHERE email = '$email'");

while( $row = mysql_fetch_array( $result ) )
{

$lp = $row[ "lp" ];
echo "<p>";
echo $row[ "year" ] . " ";
echo $row[ "make" ] . " ";
echo $row[ "model" ] . "   ";
echo "<form action=\"editvehicle.php\" method=\"POST\">";
echo "<input name=\"lp\" type=\"hidden\" id=\"lp\" value=\"$lp\">";
echo "<input name=\"submit\" type=\"submit\" value=\"Edit Vehicle\">";
echo "</form>";

echo "<form action=\"deletevehicle.php\" method=\"POST\">";
echo "<input name=\"email\" type=\"hidden\" id=\"lp\" value=\"$email\">";
echo "<input name=\"lp\" type=\"hidden\" id=\"lp\" value=\"$lp\">";
echo "<input name=\"$lp\" type=\"submit\" value=\"Delete\">";
echo "</form>";
echo "</p>";

}

?>

 

Page 2:

<?php
include("conf.inc.php"); // Includes the db and form info.

$email=$_POST['email'];
$lp=$_POST['lp'];

mysql_query("DELETE FROM vehicles WHERE email = '$email' AND lp = '$lp'");
header("Location: members.php");
?>

 

I was trying to make it way harder than it really was, as I usually do.  Thanks for your help.

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.