validation image

Posted on 2007-10-05
Last Modified: 2013-12-13
I have this code to validate user enty for image with number
can you tell me what's wrong with this code


$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;
        return $images;

    return false;

function check() {
@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);
/*  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;
    } */




<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">

  <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">

<tr><td class="input" align="center">
<input class="submit" name="fcode" type="image" src="../layout/en-form.gif" alt="Send" />

Question by:usmbay
    LVL 20

    Expert Comment

    whats the error u are getting ?
    and replace


    Author Comment

    I'm not getting anything I git a blank page
    I should get what I echo
    is the construction of the script is correct??
    LVL 20

    Accepted Solution

    uncheck the http friendly url from IE:
    Tools > Internet Options > Advanced > Uncheck "show friendly http error message"
    and reload you page u will see the eror if any

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
    Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP. provides powerful tools for surveying targeted groups, and utilizing data from completed surveys to find trends, discover areas of demand or customer expectation, and make business decisions on products or services.

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now