how to delete a row like this
Moderator: General Moderators
how to delete a row like this
hello,
can someone help me i need to make a SQL code that deletes a row WHERE id = 5 AND WHERE name = mouse
i basically need to make a SQL code that will delete a row but i need 2 WHERE statements in it.
can someone help me i need to make a SQL code that deletes a row WHERE id = 5 AND WHERE name = mouse
i basically need to make a SQL code that will delete a row but i need 2 WHERE statements in it.
Re: how to delete a row like this
Code: Select all
DELETE FROM tablename WHERE id = 5 AND name = 'mouse'Re: how to delete a row like this
ok i got that down can you help me incorporate variables in my sql code..
my code right now
my code right now
Code: Select all
$order = "DELETE FROM $DB2 WHERE ClientID = $CID AND email = $email;
Re: how to delete a row like this
right now i got
i know my connections are good. right now i am getting input data is fail.. which means the SQL code is failing.
in my DB ID is a INT column and email is a TINYTEXT column. any ideas?
i echoed $order to see my SQL was good with my added variables.. i know for sure i am trying to delete a row that has this data in it in those columns.
Code: Select all
<?php
$CID = $_GET['CID'];
$email = $_GET['email'];
$DB2 = $_GET['DB'];
mysql_connect("localhost","username","password");//database connection
mysql_select_db("database");
$order = "DELETE FROM '$DB2' WHERE ID = '$CID' AND email = '$email'";
$result = mysql_query($order);
if($result)
{
echo("
Input data is succeed");
}
else
{
echo("
Input data is fail");
}
echo $order;
?>
in my DB ID is a INT column and email is a TINYTEXT column. any ideas?
i echoed $order to see my SQL was good with my added variables.. i know for sure i am trying to delete a row that has this data in it in those columns.
Re: how to delete a row like this
Lose the quotes around the table name. You want back ticks there instead.
Also escape your inputs, don't use mysql_ functions, use prepared statements, etc.
Also escape your inputs, don't use mysql_ functions, use prepared statements, etc.
Re: how to delete a row like this
Code: Select all
<?php
$CID = $_GET['CID'];
$email = $_GET['email'];
$DB2 = $_GET['DB'];
mysql_connect("localhost","username","password");//database connection
mysql_select_db("database");
$order = "DELETE FROM `$DB2` WHERE ID = '$CID' AND email = '$email'";
$result = mysql_query($order);
if($result)
{
echo("
Input data is succeed");
}
else
{
echo("
Input data is fail");
}
echo $order;
?>
the db username has the appropriate authority level
Last edited by donny on Tue Aug 26, 2014 6:44 am, edited 1 time in total.
Re: how to delete a row like this
How does it not work? What does mysql_error() say? Have you checked that all the variables contain values?
Re: how to delete a row like this
yes i have checked the variables are correct.. i echoed the sql code to make sure they were in there too and they're showing up. i made sure the data does exists in the db and what I'm trying to delete actually exist.. can you tell ne how to add mysql error reporting.
Re: how to delete a row like this
Instead of echoing "Input data is fail", echo mysql_error()
Re: how to delete a row like this
Unknown column '8431' in 'where clause'
it's saying $CID value is the column when that should be row data under column ID
column names are ID and email and the $variables are data that should be in the rows... both $variable contents are on the same row and my column names are correct
it's saying $CID value is the column when that should be row data under column ID
column names are ID and email and the $variables are data that should be in the rows... both $variable contents are on the same row and my column names are correct
Re: how to delete a row like this
i ran the SQL query in phpmyadmin and it deleted it no problem
Re: how to delete a row like this
i fixed it
Query had to look like this
Query had to look like this
Code: Select all
$order = "DELETE FROM `$DB2` WHERE `ID` = '$CID' AND `email` = '$email'";