Is this code correct?

Discussion in 'PHP' started by moin, Apr 27, 2007.

  1. #1
    Hello friends,

    The logic is to retrieve all the videos from the database and play them in the browser.

    <?php
    
    $con=mysql_connect("localhost","root","");
    
    if(!$con)
    {
    mysql_error();
    }
    
    mysql_select_db("my_upload",$con);
    
    $result = mysql_query("SELECT * FROM upload");
    
     $assoc = mysql_fetch_assoc( $result );
    
    $videofolder = './upload/';
    while($row = mysql_fetch_array($result))
      {
      $vid1= $row['vid_name'];
      if (!preg_match('/\.(mpg|wmv|avi)$/i', $vid1) OR !file_exists($videofolder . $vid1))
    {
         exit();
    }
      echo "<img dynsrc=$videofolder . $vid1 WIDTH=400 HEIGHT=200 type=application/mpg/>";
    
      echo "<br/>";
    
      }
    mysql_close($con);
    ?>
    Code (markup):
    I need help as quickly as possible,
     
    moin, Apr 27, 2007 IP
  2. jestep

    jestep Prominent Member

    Messages:
    3,659
    Likes Received:
    215
    Best Answers:
    19
    Trophy Points:
    330
    #2
    It looks fine to me.

    I would add start="FILEOPEN" and fix a few things to make the html valid.

    
    
    echo '<img dynsrc="'.$videofolder.$vid1.'" width="400" height="200" start="FILEOPEN" type="application/mpg/">';
    
    
    PHP:
     
    jestep, Apr 27, 2007 IP
  3. lwbbs

    lwbbs Well-Known Member

    Messages:
    331
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    108
    #3
    Add exit if can't connect to database server.
    
    if(!$con)
    {
         mysql_error();
         exit();
    }
    
    PHP:
     
    lwbbs, Apr 27, 2007 IP