elmas156 Posted August 28, 2008 Share Posted August 28, 2008 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 ?> Quote Link to comment https://forums.phpfreaks.com/topic/121636-solved-delete-from-database-in-while-loop/ Share on other sites More sharing options...
unrelenting Posted August 28, 2008 Share Posted August 28, 2008 Try just DELETE FROM rather than DELETE * FROM Quote Link to comment https://forums.phpfreaks.com/topic/121636-solved-delete-from-database-in-while-loop/#findComment-627482 Share on other sites More sharing options...
elmas156 Posted August 28, 2008 Author Share Posted August 28, 2008 I tried that too, before I posted the thread, but I still get nothing. Any other ideas? Quote Link to comment https://forums.phpfreaks.com/topic/121636-solved-delete-from-database-in-while-loop/#findComment-627483 Share on other sites More sharing options...
unrelenting Posted August 28, 2008 Share Posted August 28, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/121636-solved-delete-from-database-in-while-loop/#findComment-627485 Share on other sites More sharing options...
elmas156 Posted August 28, 2008 Author Share Posted August 28, 2008 OK, you were right, it works without the if/else statements. Are there any ideas on how to make it the code work that I have written? There has to be a way to do it. Quote Link to comment https://forums.phpfreaks.com/topic/121636-solved-delete-from-database-in-while-loop/#findComment-627490 Share on other sites More sharing options...
unrelenting Posted August 28, 2008 Share Posted August 28, 2008 OK, you were right, it works without the if/else statements. Are there any ideas on how to make it the code work that I have written? There has to be a way to do it. Can you explain better what this code is trying to do? Quote Link to comment https://forums.phpfreaks.com/topic/121636-solved-delete-from-database-in-while-loop/#findComment-627499 Share on other sites More sharing options...
elmas156 Posted August 28, 2008 Author Share Posted August 28, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/121636-solved-delete-from-database-in-while-loop/#findComment-627509 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.