Howdy, I appreciate any help I can get.

I am trying to build a simple PHP script that will append links to video files on a simple PHP page. The page already has video links posted, but the admin (idealy) will have to open a page that has a "name of video" field, "description of video field" then a path of file field. This would the add a link to the path file in addition to the rest of the file links...the simpler, the better.

Can anyone steer me in the right direction? I've searched for days...

Many thanks,

    You were probably having trouble searching for a solution because the problem is so generic 🙂 But a good question, nonetheless.

    All you really need to do is store those 3 items (name, description, file path) in a database (perhaps MySQL), access the information with a query, and then output the results of that query in the HTML portion of the page.

    It's kind of hard to provide any sample code because any such code would be contingent upon how you set-up the database. For something this simple, you just need one table with three columns. I'll try my best.

    If you can get as far as setting up the database table, then this should be enough to get you started.

    //I assume that you have alread established a connection to the MySQL database
    //and have already selected the table with which you're intending to work
    //(in this case, the `videos` table). If you're unsure of how to connect to the
    //database and select a table, have a look at the MySQL Function section of
    //the PHP Reference Manual.
    
    //In this example, I assume that your column names on said table are as follows:
    //name
    //description
    //path
    
    //Also, I'm not sure if your "name" column is referring to the name of the file,
    //or the title of the video. I have assumed the title of the video in the example.
    
    //Form the MySQL query.
    $query = 'SELECT * FROM `videos`';
    
    //Execute the query and store the result as a PHP resource.
    $result = mysql_query($query) or die(mysql_error());
    
    //Iterate through each result in the set and print the HTML code
    //required to create the description and link.
    while ($row = mysql_fetch_assoc($result)) {
    	echo '<a href="' . $row['path'] . '">' . $row['name'] . '</a>';
    	echo '<br />' . $row['description'];
    }
    

    The "admin" interface will be easy enough to implement, assuming you have some kind of log-in process in-place. Assuming you do, really, all you need is a (secure) form with three fields - one for each column - in which the admin can type the necessary values. Once the admin has filled-out the form, you would submit the form to a PHP page (even to itself) and insert the input into the database table. We can help you with that part, too.

      Write a Reply...