Php projects not working(wamp server)

Discussion in 'PHP' started by vivek_master146, Jun 30, 2012.

  1. #1
    I am new to PHP. I have downloaded several php projects from source code websites to learn php but most of the php projects which are based on database are not working. I am using WAMP server. Its not showing any error but its not working. I have also created appropriate database with correct table name using .sql file through phpmyadmin but i can't figure out the reason why its not working. These projects are rated good and got very good feedback from users. But its not working for me.

    I am using php 5.3 and mysql is 5.5.20.

    Can i upload the code here with filenames ?
     
    vivek_master146, Jun 30, 2012 IP
  2. akhileshbc

    akhileshbc Active Member

    Messages:
    98
    Likes Received:
    1
    Best Answers:
    5
    Trophy Points:
    75
    #2
    Have you set the database config like username, password, databasename and host ?

    By default, host would be localhost, db user would be root, password would be empty and database name will be the name of the database you have created.

    Are you able to run other projects(db based as well as pure PHP) ? Can you tell us what you see when you access the script ? Is it blank ? Did you checked the logs folder inside where you have installed the WAMP ?
     
    akhileshbc, Jun 30, 2012 IP
  3. vivek_master146

    vivek_master146 Peon

    Messages:
    134
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Yes, everything is configured. Few simple projects(db based) are working. But the projects which are using binary large objects are not working. I think it has to do something with BLOB. Maybe, i have to enable few php extensions. The project which i am accessing have everything configured. I have also create the database with proper structure as per .sql file. But its not working. After uploading the images , its showing no images. There are two php files in the project whose contents are given below:-

    Contents of image.php page

    <? // map field in the maps table is of longblob type
    @mysql_connect("localhost", "root", "")
    or die("Could not connect to MySQL server!");
    @mysql_select_db("binary_data") or die("Could not select binary_data database!");
    ?>
    <?php
    if (empty($_GET['id'])) {
    $result = mysql_query("SELECT id FROM binary_data");
    if (mysql_num_rows($result)== 0) {
    print "No images!\n";
    print "<a href=\"storeImage.php\">Click here to add one <a>\n";
    exit;
    }
    $x=0;
    print "<h2 style=\"color:#456799;\">Click on a link to View the Image</h2>";
    while ($x < mysql_numrows($result)) :
    $id = mysql_result($result, $x, 'id');
    print "<a href=\"$_SERVER[PHP_SELF]?id=$id\">image $id</a><br />\n";
    $x++;
    endwhile;
    exit;
    }
    
    $result = mysql_query("SELECT bin_data,filetype FROM binary_data WHERE id = " . $_GET['id']);
    $x=0;
    while ($x < mysql_numrows($result)) :
    $foto = mysql_result($result, $x, 'bin_data');
    $foto=stripslashes(base64_decode($foto));
    $type = mysql_result($result, $x, 'filetype');
    if (strtolower($type=="image/pjpeg")) $type="image/jpeg";
    header("Content-type: $type");
    print $foto;
    $x++;
    endwhile;
    mysql_close();
    ?>
    
    PHP:


    Contents of storeimage.php


    
    <?php
    $PageTitle="Add Image To The Gallery?";
    
    if (isset($_POST['Submit'])){
     // store image into db
     print "hio";
     mysql_connect("localhost","root","") or die ("");
     mysql_select_db("binary_data") or die ("");
    
     $description="My Image Description";  
    
     foreach ($_FILES["pictures"]["error"] as $key => $error) {
       if ($error == UPLOAD_ERR_OK) {
           $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
           $filename = $_FILES["pictures"]["name"][$key];
           $type = $_FILES["pictures"]["type"][$key];
    	   $size=$_FILES["pictures"]["size"][$key];
    	   print $type."<br>";
           $data=base64_encode(addslashes(fread(fopen($tmp_name, "r"), filesize($tmp_name)))); //binary data
           $filename=addslashes($filename);
           $description=addslashes($description);
           $insStr="INSERT INTO binary_data(description,bin_data,filename,filetype,filesize) VALUES('$description','$data','$filename','".
             "$type','$size');";
           $result = mysql_query($insStr) or die(mysql_error());
       }
     }
     mysql_close();
    
     //echo $insStr;
     print $filename. "  *  " .$type. "   *   " .$size;
     //print "<br>";
    
     $PageTitle="Image Added To The Gallery ::: ".$PageTitle;
    }
    ?>
    
    <html>
    <head>
    <title><?php echo $PageTitle; ?></Title>
    </head>
    <body>
    
    <form action="" method="post" enctype="multipart/form-data">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    <p>Add Pictures:
    <input type="file" name="pictures[]" />
    <input type="file" name="pictures[]" />
    <input type="file" name="pictures[]" />
    <input type="submit" value="Send" name="Submit"/>
    </p>
    </form>
    
    </body>
    </html>
    
    PHP:
    Contents of .sql file:-
    
    create database binary_data;
    use binary_data;
    CREATE TABLE binary_data (
    id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY,
    description CHAR(50),
    bin_data LONGBLOB,
    filename CHAR(50),
    filesize CHAR(50),
    filetype CHAR(50)
    );
    
    Code (markup):
     
    vivek_master146, Jun 30, 2012 IP
  4. gombile13

    gombile13 Active Member

    Messages:
    136
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    63
    #4
    what result you see on your display? is it just a blank page?
    try to change the php error_reporting to All in your php.ini file

    tell me what you get?
     
    gombile13, Jun 30, 2012 IP
  5. NetStar

    NetStar Notable Member

    Messages:
    2,471
    Likes Received:
    541
    Best Answers:
    21
    Trophy Points:
    245
    #5
    You are using root with no pass to log in to your database from a script? That can't be right...

    I see the script is also vulnerable to SQL Injection. Using that script opens you up to be hacked.
     
    NetStar, Jun 30, 2012 IP