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 Link to comment https://forums.phpfreaks.com/topic/48184-solved-a-simple-question/ 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? Link to comment https://forums.phpfreaks.com/topic/48184-solved-a-simple-question/#findComment-235535 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? Link to comment https://forums.phpfreaks.com/topic/48184-solved-a-simple-question/#findComment-235538 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 Link to comment https://forums.phpfreaks.com/topic/48184-solved-a-simple-question/#findComment-235542 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']}'"); Link to comment https://forums.phpfreaks.com/topic/48184-solved-a-simple-question/#findComment-235544 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 Link to comment https://forums.phpfreaks.com/topic/48184-solved-a-simple-question/#findComment-235546 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'"); Link to comment https://forums.phpfreaks.com/topic/48184-solved-a-simple-question/#findComment-235549 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 Link to comment https://forums.phpfreaks.com/topic/48184-solved-a-simple-question/#findComment-235555 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.