is_numeric

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Fillmorejd
Forum Newbie
Posts: 1
Joined: Thu Jun 09, 2005 3:21 pm

is_numeric

Post by Fillmorejd »

I'm writing a database applecation that insert update and deletes from a database. I have the whole thing writed but I have a bug with deleting row with an ID over 60 to 70. The way I have it working is when you want to delete a row the application uses the ID as the value of a checkbox. The id is then the varabile used to delete the row in the next page.

First page:

Code: Select all

$query = "select * from database where name='$name'";
$res = mysql_query($query);
if($res){
	while($row=mysql_fetch_assoc($res)){
	echo "<tr>";
	echo "<td> <input type='checkbox' Name='", $row[id] , "' value='", $row[id] , "'></input></td>"; 
	echo "<td>" , $row["name"] ,"</td></tr>";
	}
}
else{
	echo "<br />Resource not available";
}
Second page:

Code: Select all

$arr = get_defined_vars();
$count = count($arr);
for($i=0;$i<$count;$i++){
	if(is_numeric($arr[$i])){
		$query = "delete from database where id='$arr[$i]'";
		mysql_query($query);
		echo "Record " , $arr[$i] , " has been deleted\n";
	}
}
mysql_close($conn);
?>
As you can see I just get the defined_vars run them through a loop and use the numeric ones to delete the correct row. It works great on the lower numbered ID but it does not work with ID's of around 60 or higher.

any help would be great.

JCART | Please use

Code: Select all

tags when posting php code. Review [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color][/size]
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Be veeerrrryyy careful with the way you've got this working. There is great potential here for someone to define a variable with a number value, which would automatically make you delete an associated row. I would suggest that you change the checkbox names from just numbers, to a slightly specialized name, such as delete_XX.

Then, on the second page, don't call get_defined_vars, just loop through $_POST instead.


As for the problem you actually asked about :), I can see no reason why you should be having such a difficulty. Output the query, and examine that. It may not be what you think it should be.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
method_man
Forum Contributor
Posts: 257
Joined: Sat Mar 19, 2005 1:38 am

Post by method_man »

use php tags from now on
Post Reply