Jump to content

[SOLVED] no number in verable, error message output


crawlerbasher

Recommended Posts

Well I'm kind of lost on this one.

I've been looking all over to try and find a way to remove all cracters accept numbers from a verable.

 

And I'm kind of new, when it comes to removing certain caracters from the verable.

 

an eg would be

 

$id = 00289 // Good verable

$id = ".Some hacking going on." // Bad Verable

 

So since I only need numbers to past though the verable, any idea of the best way to solve this?

If you only want to check if it's a number, use is_numeric

<?php
$var = 1;
if (is_numeric($var)) echo 'is number';
else echo 'is not a number';

$var = 'hello world';
if (is_numeric($var)) echo 'is number';
else echo 'is not a number';
?>

 

If you only want to accept a number use intval that converts strings into numbers:

<?php
$var = 'hello';
$var = intval($var); //becomes 0

$var = '23';
$var = intval($var); //becomes 23
?>

Well this is my code and still not working.

 

<?php
include("../header.php");
$id = $_GET['id'];
if (is_numeric($id)) {
echo "<p align=\"center\">\n";
echo "<img src=\"http://www.stateofmind.me.uk/images/cineworld/starwars/DSC".$id.".jpg\" alt=\"DSC".$id."\" border=\"0\" />\n";
echo "<br />\n";
echo $id;
echo "<br /><br />\n";
echo "<a href=\"/cineworld/startwars.php\">Back</a>\n";
echo "</p>";
} else {
echo "That is not a numeric value\n";
}
include("../footer.php");
?>

 

with number string and caracters it still outpost as that is not a numeric value.

The only error message are from the include function which is because for that pertiacal header and footer, are not on the site, I'm just testing the main code it self.

 

Which gives these message:

 

$id = 00127 // output is: That is not a numeric value

$id = test // output is: That is not a numeric value

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.