usmbay
asked on
validation image
I have this code to validate user enty for image with number
can you tell me what's wrong with this code
<html>
<head>
</head>
<body>
<?php
$path_to_images = "./images/"; // path to your images
$default_img = "image1.jpg"; // image to display if directory listing fails
function getRandomImage($path, $img) {
if ( $list = getImagesList($path) ) {
mt_srand( (double)microtime() * 1000000 );
$num = array_rand($list);
$img = $list[$num];
}
return $path . $img;
}
function getImagesList($path) {
$ctr = 0;
if ( $img_dir = @opendir($path) ) {
while ( false !== ($img_file = readdir($img_dir)) ) {
// can add checks for other image file types here
if ( preg_match("/(\.gif|\.jpg) $/", $img_file) ) {
$images[$ctr] = $img_file;
$ctr++;
}
}
closedir($img_dir);
return $images;
}
return false;
}
function check() {
$username="root";
$password="sp4ce23";
$database="databse";
$imageName=$_GET['$imgs'];
echo('$imgs');
mysql_connect(localhost,$u sername,$p assword);
@mysql_select_db($database ) or die( "Unable to select database");
$result=mysql_query('SELEC T imageValue1,imageName FROM images WHERE imageName="$imageName" and imageValue="fcode"');
print( $default_img);
echo($default_img);
/* if($result ) return true;
else {
alert("Le code de validation que vous avez entré est incorrect. Veuillez essayer de nouveau.\n"+
"\n The validation code you have entered is incorrect. Please try again." );
return false;
} */
mysql_close();
}
echo($default_img);
?>
<form name="data" method="post" action="display.php?t=send #form" enctype="multipart/form-da ta" onsubmit="return check();">
<table class="form" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center">
<input type="text" size="7" name="fcode"> & nbsp; <img src="<?php echo getRandomImage($path_to_im ages, $default_img) ?>" alt="" width="90" height="30">
</td>
</tr>
<tr><td class="input" align="center">
<input class="submit" name="fcode" type="image" src="../layout/en-form.gif " alt="Send" />
</td></tr>
</table>
</form>
</body>
</html>
can you tell me what's wrong with this code
<html>
<head>
</head>
<body>
<?php
$path_to_images = "./images/"; // path to your images
$default_img = "image1.jpg"; // image to display if directory listing fails
function getRandomImage($path, $img) {
if ( $list = getImagesList($path) ) {
mt_srand( (double)microtime() * 1000000 );
$num = array_rand($list);
$img = $list[$num];
}
return $path . $img;
}
function getImagesList($path) {
$ctr = 0;
if ( $img_dir = @opendir($path) ) {
while ( false !== ($img_file = readdir($img_dir)) ) {
// can add checks for other image file types here
if ( preg_match("/(\.gif|\.jpg)
$images[$ctr] = $img_file;
$ctr++;
}
}
closedir($img_dir);
return $images;
}
return false;
}
function check() {
$username="root";
$password="sp4ce23";
$database="databse";
$imageName=$_GET['$imgs'];
echo('$imgs');
mysql_connect(localhost,$u
@mysql_select_db($database
$result=mysql_query('SELEC
print( $default_img);
echo($default_img);
/* if($result ) return true;
else {
alert("Le code de validation que vous avez entré est incorrect. Veuillez essayer de nouveau.\n"+
"\n The validation code you have entered is incorrect. Please try again." );
return false;
} */
mysql_close();
}
echo($default_img);
?>
<form name="data" method="post" action="display.php?t=send
<table class="form" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center">
<input type="text" size="7" name="fcode"> &
</td>
</tr>
<tr><td class="input" align="center">
<input class="submit" name="fcode" type="image" src="../layout/en-form.gif
</td></tr>
</table>
</form>
</body>
</html>
ASKER
I'm not getting anything I git a blank page
I should get what I echo
is the construction of the script is correct??
Thanks
I should get what I echo
is the construction of the script is correct??
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
and replace
mysql_connect(localhost,$u
with
mysql_connect("localhost",