Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Every body
i am new on php .. but i do well for now
i have problem with called stored procedure

Stored Procedure
SQL
CREATE DEFINER=`root`@`localhost` PROCEDURE `spr_StdDelete`(IN ID INT)
BEGIN


DELETE FROM students WHERE ID=@ID;


END


its work good on my sql but when i call it on php its delete all row .. and this is the problem
i want delete selected row


PHP
<?php
include('config.php');

if (isset($_GET['ID']) && is_numeric($_GET['ID']))
{
$ID = $_GET['ID'];

$result = mysql_query('Call spr_StdDelete("$ID")')
or die(mysql_error());


header("Location: view.php");
}
else

{
header("Location: view.php");
}
?>


and if i use this query its work and delete just selected row

PHP
$result = mysql_query("DELETE FROM students WHERE ID=$ID")
or die(mysql_error());
Posted
Updated 4-Feb-14 4:28am
v4

1 solution

mysql is not case sensitive, so in the stored procedure:
DELETE FROM students WHERE ID= id;

"WHERE ID = id" is always true, that causes deletion of all rows. Rename the id will solve this problem.
 
Share this answer
 
v3
Comments
Member 10405755 4-Feb-14 10:30am    
Hello
i am try this

CREATE DEFINER=`root`@`localhost` PROCEDURE `spr_StdDelete`(IN ID INT)
BEGIN


DELETE FROM students WHERE ID=@ID;


END

becuz i am let ID as parameter(@ID) but still delete all table
Peter Leow 4-Feb-14 11:22am    
Are you sure? Try this:
CREATE PROCEDURE spr_StdDelete(IN para INT)
BEGIN
DELETE FROM students WHERE ID=para;
END
Member 10405755 5-Feb-14 2:22am    
yes i am sure

this is my stored procedure

DELIMITER $$

CREATE DEFINER=`root`@`localhost` PROCEDURE `spr_StdDelete`(IN ID INT)
BEGIN


DELETE FROM students WHERE ID=@ID;


END


and i call it like this

$result = mysql_query("Call spr_StdDelete('$ID')")
or die(mysql_error());

** ($ID) its query string from another page.
still not delete plz help
Peter Leow 5-Feb-14 3:03am    
Why is it @ID when the argument is ID?
Why do you need to quote the $ID in spr_StdDelete('$ID')?
Member 10405755 5-Feb-14 4:44am    
i solve it

CREATE DEFINER=`root`@`localhost` PROCEDURE `spr_StdDelete`(IN STUDENT_ID INT)
BEGIN


DELETE FROM students WHERE id=STUDENT_ID;


END

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900