Page 1 of 1

is_numeric

Posted: Thu Jun 09, 2005 3:29 pm
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]

Posted: Thu Jun 09, 2005 4:42 pm
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.

Posted: Thu Jun 09, 2005 8:04 pm
by method_man
use php tags from now on