Link to home
Start Free TrialLog in
Avatar of usmbay
usmbayFlag for United States of America

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,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

$result=mysql_query('SELECT 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-data" onsubmit="return check();">
<table class="form" border="0" cellspacing="0" cellpadding="0">

<tr>
  <td align="center">
    <input type="text" size="7" name="fcode">&nbsp;&nbsp;&nbsp; <img src="<?php echo getRandomImage($path_to_images, $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>
Avatar of Emad Gawai
Emad Gawai
Flag of United Arab Emirates image

whats the error u are getting ?
and replace
mysql_connect(localhost,$username,$password);
with
mysql_connect("localhost","$username","$password");

Avatar of usmbay

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
ASKER CERTIFIED SOLUTION
Avatar of Emad Gawai
Emad Gawai
Flag of United Arab Emirates image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial