Shiven
Shiven

Reputation: 206

cannot execute the delete query

I have two tables : details and Product

Both the tables have a field user_id. It is the primary key in the table order and in the table Product i have created a foreign key.I execute the following query. Initially the tables had two records one with user_id=11 and and other with user_id=12 I executed the following script

// making the database connection
$db2=mysql_connect("localhost","root","");
mysql_select_db("my_requests",$db2);
$query=mysql_query("SELECT details.*,product.* FROM details INNER JOIN product ON details.user_id = product.user_id"); 


while($row=mysql_fetch_array($query)){
$id=$row['user_id'];
echo "$id";

$query1=mysql_query("DELETE FROM details WHERE details.user_id=$id");    
$query2=mysql_query("DELETE FROM product WHERE product.user_id=$id");
}

On execution it just deleted the record with user_id=12. When i tried to execute it again neither did it echo anything nor did it delete the remaining record.

please rectify.sorry for the bad english.

i printed this at the end of the loop:

printf("Records deleted: %d\n", mysql_affected_rows());

It did not display anything

Upvotes: 0

Views: 218

Answers (2)

Zuber Surya
Zuber Surya

Reputation: 869

mysql_affected_rows() to check affected id

and i think your database do not have anything to display on second run

Upvotes: 0

Gntem
Gntem

Reputation: 7155

try to use mysql_affected_rows() this way you can be sure if Rows are getting delete , DELETE query would succeed even if no rows are affected

Upvotes: 1

Related Questions