Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 233
  • Last Modified:

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>
0
usmbay
Asked:
usmbay
  • 2
1 Solution
 
GawaiCommented:
whats the error u are getting ?
and replace
mysql_connect(localhost,$username,$password);
with
mysql_connect("localhost","$username","$password");

0
 
usmbayAuthor Commented:
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
0
 
GawaiCommented:
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
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now