help brushing up my code

Discussion in 'PHP' started by worldy, Jun 14, 2010.

  1. #1
    Hey guys, I'm new to php. I'm having some trouble querying my mysql database. Below what I'm trying to do is I have a variable "$videourl" which is the path of a video file on my server. The path itself is stored in the database. And based on the url of the video I want to be able to pull the associated video title. But I'm having no luck. Any pointers would be appreciated.

    
    <?php
    $videourl = $_GET['videourl'];
    echo $player;
    
    $query = mysql_query("SELECT $videourl FROM videos");
    while ($row = mysql_fetch_assoc($query)) {
    $videoTitle = $row['video_title'];
    }
    ?>
    
    PHP:

     
    worldy, Jun 14, 2010 IP
  2. lukeg32

    lukeg32 Peon

    Messages:
    645
    Likes Received:
    19
    Best Answers:
    1
    Trophy Points:
    0
    #2
    You have a few problems in your code.

    echo $player; 
    PHP:
    This hasnt been delcared/ init yet.

    Also, your SQL should probably be something like;

    $query = mysql_query("SELECT video_title FROM videos where video_url = '$videourl'");
    PHP:
    You almost certainly want to make sure you validate the data in $_GET['videourl'] too, even more so if it is user entered data or accessible to the outside world.
     
    lukeg32, Jun 14, 2010 IP
  3. bugcoder

    bugcoder Peon

    Messages:
    59
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    
    you are not giving field name of table which is containing videourl record
    <?php
    $videourl = $_GET['videourl'];
    echo $player;
    
    $query = mysql_query("SELECT fieldname = '$videourl' FROM videos");
    while ($row = mysql_fetch_assoc($query)) {
    $videoTitle = $row['video_title'];
    }
    ?>
    
    PHP:
     
    bugcoder, Jun 14, 2010 IP
  4. worldy

    worldy Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks for the help
     
    worldy, Jun 14, 2010 IP