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:
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.
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: