Jump to content

[SOLVED] A simple question


npsari

Recommended Posts

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

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

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

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']}'");

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.