-2

I'm trying to download a PowerPoint file. I'm saving its path in column slide in a table called lesson. Whenever I try to download it, it downloads the whole table.

All I want is the column slide, how can I do that?

// connect to the database
$link = mysql_connect('localhost','root','');

if (!$link) {
    die('Could not connect :' . mysql_error());
}

$Selected= mysql_select_db("elearningg", $link);

if (!$Selected) {
    die("Could not connect: " . mysql_error());
}

// query the server for the file
$L_ID = $_GET['id'];
$query = "SELECT * FROM lesson WHERE LID = '$L_ID'";
$result  = mysql_query($query) or die(mysql_error());

// define results into variables
$name=mysql_result($result,0,"Lname");
$content=mysql_result($result,0,"slide");

header("Content-disposition: attachment; filename=$name");

echo $content;

mysql_close();
Bas Peeters
  • 3,269
  • 4
  • 33
  • 49
  • 1
    Again another user using Evil **`mysql_* `** . Please Stop it !! – Pratik Joshi May 09 '15 at 08:00
  • if I used mysqli_ it'll be fixed? – Noura Mohammed May 09 '15 at 08:10
  • i'm not sure about the way I wrote the code – Noura Mohammed May 09 '15 at 08:11
  • 1
    _"it download the whole table"_ what table? _"all I want is the column slide"_ you mean, you want to extract that particular slide from the file? – someOne May 09 '15 at 08:23
  • What is a column slide? – Toby Allen May 09 '15 at 08:25
  • He means the column's name is `slide`. – Bas Peeters May 09 '15 at 08:28
  • (slide is a folder ) contains files and i want the file that belongs to a specific lesson name that why i'm saving it in the same table – Noura Mohammed May 09 '15 at 08:28
  • **Danger**: You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are also **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin May 09 '15 at 08:42
  • well then, if `$content` is the name of the folder, and `$name` is the name of the file, then you may change the arguments to the `header` function to `header("Content-disposition: attachment; filename=$content/$name");` – someOne May 09 '15 at 09:03
  • use mysqli_* functions instead of mysql_* functions – Sourabh Kumar Sharma May 30 '15 at 06:21

1 Answers1

0

If all you want is the column slide, you have to select only that column in your select clause. Right now you're selecting all of the table's columns by using SELECT *.

Try this:

$query = "SELECT slide FROM lesson WHERE LID = '$L_ID'";

That should only return the column slide from table lesson.

Bas Peeters
  • 3,269
  • 4
  • 33
  • 49
  • Yes, but I see in your code that you're also using the column `Lname`, so you should probably do `SELECT slide, Lname FROM lesson`. – Bas Peeters May 09 '15 at 08:33