Jump to content

[SOLVED] Deleting Rows from mysql


jaybeeb

Recommended Posts


<?php
mysql_connect("localhost", "root", "") or die ("Could not connect");
mysql_select_db("itsupport") or die ("Could not connect to DB");
if ($_GET['User_ID']) {
echo $_GET['User_ID'];

    $User_ID = $_GET['User_ID'];
    $query = "DELETE FROM itsupport WHERE User_ID='$User_ID'"; // define the query string
    mysql_query(query) or die(mysql_error());
echo "DELETE FROM itsupport WHERE User_ID='$User_ID'"; 
echo "The Row Number $User_ID has been Successfully Removed";
}
?>

Link to comment
Share on other sites

Hey : Try sumit like this.

 

<?php 
                    // other script stuff

if($_GET['User_ID']) 
{
            $User_ID = $_GET['User_Id'];
            $sql = ""DELETE FROM itsupport WHERE User_ID='{$User_ID}'";  
            mysql_query($sql) or die('error');
		echo " deleted";
} 



 

I used a small d in ID try with a uppercase D see if makes a diff

Link to comment
Share on other sites

You are STILL saying mysql_query(query) instead of mysql_query($query) like 2 different people have suggested.

 

Do this and see what happens.

<?php
mysql_connect("localhost", "root", "") or die ("Could not connect");
mysql_select_db("itsupport") or die ("Could not connect to DB");
if (isset($_GET['User_ID'])) {
    //echo $_GET['User_ID']."<br />";
    $User_ID = $_GET['User_ID'];
    $query = "DELETE FROM `itsupport` WHERE `User_ID`='$User_ID'"; // define the query string
    //echo $query."<br />";
    $result = mysql_query($query) or die (mysql_error());
    if (mysql_affected_rows($result))
    {
        echo "The Row Number $User_ID has been Successfully Removed.";
    }
    else
    {
        echo "No rows affected."
    }
}
else
{
    echo "User_ID is not set to anything.";
}
?>

Link to comment
Share on other sites

Yes I forgot a ; there wasn't an extra } though.

 

And if you're going to post an error message, you need to post the code that is giving it and show what line the error message is referencing.

 

Because I have no idea what code you're using at this point. I assume it's the code I posted, but it could be some variation that you changed.

Link to comment
Share on other sites

Got this working , code I ended up using was very similar to my update. Just posting for people who search this in the future. Thanks everybody for your help

 

<?php
require_once 'library/db.php';




if (!($conn = mysql_connect('localhost', 'root', '')))
{
	showError();
}

if (!(mysql_select_db('itsupport', $conn)))
{
	showError();
}

$a = $_GET['id'];

$query=mysql_query("delete FROM itsupport WHERE User_ID='$a'", $conn);
if ($query)
echo "The record was successfully deleted. <br><br>";
else
echo "Failed to delete the record <br><br>";



mysql_close($conn);
include 'currentissues.php';

?> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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