Hi,
I created the function below to delete a record from a MySQL table.
function Del_record($table, $id){
$query_del_record = "DELETE FROM $table WHERE $table.id = \"$id\"";
$del_record = mysql_query($query_del_record, $connection) or die(mysql_error());
}
When the function is called execution stops at the mysql_query statement. However, when I removed the function structure and pasted the code directly at the calling location, it worked fine. Moreover I have the same problem with all other custom defined functions where I've used mysql_query() irrespective of the operation involved (SELECT, INSERT, UPDATE, DELETE). Pasting the code inline is not the ideal solution for me as quite a few of the functions I'll need to use frequently are very lengthy and a hassle to reconfigure.
Is there a problem or limitation with the mysql_query() function that I am unaware of? Can anybody help make my function work? My apologies if this is a rehash of an old question, I haven't been able to find an answer after almost a whole day of searching online. Thanks in advance for your help.
Best Regards
Karthik
Trouble using mysql_query from inside a custom function
Moderator: General Moderators
-
SplothchMan
- Forum Newbie
- Posts: 2
- Joined: Mon Jul 27, 2009 4:29 pm
Re: Trouble using mysql_query from inside a custom function
$connection is out of scope.
either use global to populate it in the function scope or pass it as argument.
either use global to populate it in the function scope or pass it as argument.
There are 10 types of people in this world, those who understand binary and those who don't
-
SplothchMan
- Forum Newbie
- Posts: 2
- Joined: Mon Jul 27, 2009 4:29 pm
Re: Trouble using mysql_query from inside a custom function
VladSun,
Wow, that was fast. I took your advice and it works now. Thank you so much.
Best Regards
Karthik
Wow, that was fast. I took your advice and it works now. Thank you so much.
Best Regards
Karthik