Shane
Shane

Reputation: 244

Delete an entire row from a table, using MySQL

I am trying to code for a row to be deleted in MySQL.

I am not sure how to do this so have picked some coding up from another website:

Syntax:

<?php
$personID=$_GET["q"];
if ($personID<="0"){echo( "<center><h3><a href=\"#\" onclick=\"window.close(); return false\">NO ID ERROR CLICK THIS TO RETRY CLOSE WINDOW</a></h3></center>"); 
 }
 else
 {
 $con = mysql_connect("mysql.XXX.com","XXX","XXX");

if (!$con) 
  {
   die('Could not connect: ' . mysql_error());
   }
  $myid=$_COOKIE["user"];

@mysql_select_db("u716720408_admin", $con)or die( "Unable to select database");
$result=mysql_query("DELETE * FROM users WHERE personID=$personID")or die(mysql_error());  

$cnt=1;

$row = mysql_fetch_array( $result );

$f1=$row['personID'];
$f2=$row['personFname'];
$f9=$row['llmail'];
$f14=$row['personSname'];
$f19=$row['password']; 

?>

Upvotes: 1

Views: 6690

Answers (3)

mirkobrankovic
mirkobrankovic

Reputation: 2347

Use:

 DELETE FROM users WHERE personID=$personID

Make sure you read up about SQL Injection

Upvotes: 5

Naveen Kumar Alone
Naveen Kumar Alone

Reputation: 7668

In your result you dont need to metion * in delete query

$result = mysql_query("DELETE FROM users WHERE personID=$personID") or
     die(mysql_error());  

Upvotes: 1

user
user

Reputation: 545

You don't need the * in the delete query

try

DELETE FROM users WHERE personID=$personID

Upvotes: 3

Related Questions