npsari Posted April 22, 2007 Share Posted April 22, 2007 How can i delete a specific row from a mySQL table I want to delete Image2 (or make the value of it is nothing, NULL) <?php $con = mysql_connect("localhost","name","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("npsari_other", $con); mysql_query("DELETE Image2 FROM ads WHERE ID='$ID'"); mysql_close($con); ?> Is this code right, because it doesnt work Quote Link to comment Share on other sites More sharing options...
trq Posted April 22, 2007 Share Posted April 22, 2007 The query looks fine (even if there is a distict lake of error handling). Where are you defining $ID? Quote Link to comment Share on other sites More sharing options...
Mutley Posted April 22, 2007 Share Posted April 22, 2007 <?php $con = mysql_connect("localhost","name","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("npsari_other", $con); mysql_query("DELETE FROM ads WHERE ID='$ID'"); mysql_close($con); ?> That would delete the row where the id = $id. I'm not sure what the "Image2" part is referring too? Quote Link to comment Share on other sites More sharing options...
npsari Posted April 22, 2007 Author Share Posted April 22, 2007 Hey Thorpe... ID and Image2 come from a link (They work fine) hmm, does it have to do with this: mysql_query("UPDATE ads SET Image1= '$Image2' WHERE ID = '$ID'"); mysql_query("DELETE Image2 FROM ads WHERE ID='$ID'"); Because I rename Image1 to Image2 just before i delete Image2 Quote Link to comment Share on other sites More sharing options...
trq Posted April 22, 2007 Share Posted April 22, 2007 Sorry, didn't notice that. Mutley was right, your query should be.... mysql_query("DELETE FROM ads WHERE ID='$ID'"); However, unless you have register_globals enabled (which you should'nt) you'd need to change it to.... mysql_query("DELETE FROM ads WHERE ID='{$_GET['ID']}'"); Quote Link to comment Share on other sites More sharing options...
npsari Posted April 22, 2007 Author Share Posted April 22, 2007 Thanks Mutley and thrope But i dont want to delete the whole row, sorry I just want to delete the colomb Image2 Or make it null (empty) is there a way Quote Link to comment Share on other sites More sharing options...
Mutley Posted April 22, 2007 Share Posted April 22, 2007 If you want to delete the contents of the column "Image2" just update it to blank, such as: mysql_query("UPDATE ads SET Image2= '' WHERE ID = '$ID'"); Quote Link to comment Share on other sites More sharing options...
npsari Posted April 22, 2007 Author Share Posted April 22, 2007 Hey, good idea It passed my mind, thought i didnt try it much Now it works perfect Thanks much pal Quote Link to comment 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.