Matt Rogers
Matt Rogers

Reputation: 197

PHP - MySQL - Delete Row

I am not too sure what i am doing wrong. i am trying to delete the entire row with this code but it is not working. No error is happening it prints the line that it was deleted but when i go and have a look it is not working. Any thoughts?

<?
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("theobse1_scores", $con);

$sql="DELETE FROM times WHERE id='$id'";

if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record deleted go back to delete another!";

mysql_close($con)
?>

Upvotes: 9

Views: 97276

Answers (4)

goharkhan
goharkhan

Reputation: 21

else
    {
    $qry = "SELECT * FROM my_login WHERE email = '".$email."' LIMIT 1";
    $res = mysql_query($qry);
    if(mysql_num_rows($res) > 0)
        {
        echo "Email already exists!";
        }
    else
        {
        $qry="INSERT INTO my_login SET name='$name',city='$city',comment='$comt',password='$pass',email='$email'";
        mysql_query($qry);
        }
    }       
}
?>  

Upvotes: 2

razvan
razvan

Reputation: 61

delete.php

<?php
    include "connect.php";
    $id =$_REQUEST['id'];

    // sending query
    mysql_query("DELETE FROM utilizatori WHERE id = '$id'")
    or die(mysql_error());      

    ?>

is corect, I tested and delete from ID

and here is the button delete: `

<?<a href=\"delete.php?id=$row[id]\">Delete</a>`?>

Upvotes: 1

Matt Rogers
Matt Rogers

Reputation: 197

I got it working using this code!

<?php
$id =$_REQUEST['id'];

$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("database", $con);

// sending query
mysql_query("DELETE FROM times WHERE id = '$id'")
or die(mysql_error());      

?>

Upvotes: 7

Chibuzo
Chibuzo

Reputation: 6117

You used $order instead of your query variable $sql

$sql="DELETE FROM times WHERE id='$id'";
mysql_query($sql);

Upvotes: 10

Related Questions