Jump to content
Larry Ullman's Book Forums

DeeDee

Members
  • Posts

    26
  • Joined

  • Last visited

Everything posted by DeeDee

  1. Hey guys its been a while As I have said I will share this code on downloading files here (btw this is not complete but this is just a backbone idea of what it is, so expect some flaws on this) dataB.php <?php // if result returns false..... if ($result == 0) { echo "Dude, Where's my Files? <br>"; //...output this } else { //...output this if result returns at least 1 entry echo "<table border='1'> <tr> <td>FileEntry</td> <td>Filename</td> <td>Type</td> <td>Size(bytes)</td> <td>Time received</td> </tr>"; //iterate through the rows of the existing query for ($i = 0; $i < $rows; $i++) { $data = mysql_fetch_object($result); echo "<tr>"; echo "<td>" . $data->FileEntry. "</td>"; echo "<td>" . $data->Filename . "</td>"; echo "<td>" . $data->Filetype . "</td>"; echo "<td>" . $data->Filesize . "</td>"; echo "<td>" . $data->Received . "</td>"; echo "<td><a href='dataB.php?id=$data->id'>Collect here</a></td>"; echo "</tr>"; } echo "</table>"; } mysql_free_result($result); // releases memory mysql_close(); // closes database connection ?> dataA.php <?php $id = $_GET['id']; if ($id) { mysql_connect("myhost", "myroot", "") or die(mysql_error()); mysql_select_db("FileCollections") or die(mysql_error()); //generate queries $query = "SELECT Contents, Filetype, Filename, Filesize FROM FileData WHERE id=$id"; $result = mysql_query($query); $data = mysql_result($result, 0, "Contents"); $name = mysql_result($result, 0, "Filename"); $size = mysql_result($result, 0, "Filesize"); $type = mysql_result($result, 0, "Filetype"); // return output header("Content-type: $type"); header("Content-length: $size"); header("Content-Disposition: attachment; filename=$name"); echo $data; } ?> BTW Larry, If this has already been posted on the forum, then I apologize as I have tried to find an existing post of this otherwise I hope this will help any one in future. Thx
  2. Thanks HS I am sorry if I have mistreated your understanding in anyway. I can send an update of the written code to provide a example to anyone who wishes to learn about downloading blogs if that is okay with Larry
  3. Hey guys just to give an update that I have managed to download the file with the contents, basically I used this piece of code mysql_fetch_object(); to accomplish my task. I'll provide the link here should anyone needs it in future. http://www.w3schools.com/php/func_mysql_fetch_object.asp My humble thanks to the people who helped and replied.
  4. Yeah I do have files stored as blobs in the database but when I echo out its contents nothing is returned. I have already written data in the textfile but nothing is returned. I don't understand what I have done wrong but I'll have another look on fread to see if it works.
  5. Hi Guys just to update I managed to have the file to be downloaded however it does not display the contents of the file I will display my new code here <?php ob_start(); include('connectme.php'); $query = "SELECT name, type, size, Content FROM Files"; $result = mysql_query($query) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { $read = $row['name']; header("Content-length:" . $row['size'] . "<br>"); header("Content-type:" . $row['type'] . "<br>"); header("Content-Disposition: attachment; filename =" . basename($read) . "<br>"); echo $row['Content'] . "<br>"; readfile($read); } ob_clean(); //exit(); mysql_close(); ob_flush(); ?> Tips are appricated thank you
  6. I have restructed the code to grab the output and it returns 1 and 2. I will make adjustments to my code and let you know of my progress soon. Thanks Jon
  7. Ah byp, the final else from the first if statement is returned 'Error!!!' I was sure that this line header("Content-Disposition: attachment; name =" . $row['name']); was correct, however I don't have the appropiate book to learn from just the internet and some planning on my part. If there is a book that you can recommend me to learn more about downloading blobs via database I would be greatful. Thanks so far for your replys so far Jonathon.
  8. Hi guys I would like to request some help on a problem I am trying to solve. I am trying to download files from a database but it is only reading the file else statement. So I went about creating this code shown here. <?php if (isset($_GET['id'])) { $id = intval($_GET['id']); if ($id <= 0) { die("Connection Failed"); } else { include('connectme.php'); } $query = "SELECT name, type, size, Content FROM Files WHERE id = '$id'"; $result = mysql_query($query) or die(mysql_error()); if ($result) { if (mysql_num_rows($result) == 1) { $row = mysql_fetch_assoc($result); header("Content-length:" . $row['size']); header("Content-type:" . $row['type']); header("Content-Disposition: attachment; name =" . $row['name']); echo $row['Content']; } } else { echo "Invalid ID"; } mysql_free_result($result); } else { echo "Error!!!"; } //mysql_close(); ?>
  9. Apparently that line you told me to delete actually solved it thank you HartleySan. To answer your question on what I am doing I am selecting values from a table and then inserting them into a new table. I hope this answers your question.
  10. Hi guys I have a problem that I need some assistance with my database results is not displaying results properly for different users, leaving blank tuples in a row. Code is shown here (Ill explain a segment of code if anyone needs explaination they do not understand) Lets say I have already assigned my variables using post. <?php session_start(); include('db.php'); $UserID = $_SESSION['UserID']; $Firstname = $_POST['Firstname']; $GroupID = $_POST['GroupID']; $Surname = $_POST['Surname']; if ($UserID) { $query = "SELECT a.UserID, a.GroupID, b.Firstname, b.Surname FROM table a, table b WHERE a.UserID = b.UserID AND b.UserID LIKE '%$UserID%'"; $result = mysql_query($query); $row = mysql_fetch_array($result); while ($row = mysql_fetch_array($result)) { $UserID = mysql_real_escape_string($row['UserID']); $Firstname = mysql_real_escape_string($row['Firstname']); $Surname = mysql_real_escape_string($row['Surname']); $GroupID = mysql_real_escape_string($row['GroupID']); } $query2 = "INSERT INTO table2 (UserID, Forename, GroupID, Surname) VALUES('$UserID', '$Forename', '$GroupID', '$Surname')"; $run = mysql_query($query2) or die(mysql_error()); include('locate.php'); mysql_close(); } ?> FYI I have tested out SELECT query on mySQL and it works when the script is executed, the problem is however it does not display the results for all different logged in users. (If a simular post exists please redirect!!)
  11. Yeah I just changed back Log to datetime last night and it worked thank you both, how can i display the date and time onscreen? Say I have written the query already do I use the variable like this: echo $row['log']; or as a session echo $_SESSION['log']; Thanks
  12. I have replaced the datetime with timestamp and still does not update, but nonetheless I appricate the information you told me on timestamp, Thank you Matt.
  13. I've tried this as you said HartleySan, it still does not update the date, FEI(For Everyones Information) I am using datetime for the log function but I do not think it matters. Thanks for the suggesstion though if you do have another on mind I will welcome it.
  14. Do not worry about sessions mate that is not what I am asking. The connection is in a php file called connectme.php so that I can call from it when connecting to my database table. I hope this answers your question chris and thanks for replying.
  15. Hi guys I have a little problem of displaying the last login time via session so far I have written this: <?php session_start(); include('connectme.php'); $_SESSION['UserID'] = $UserID; $_SESSION['Log'] = $Log; $login = 'NOW()'; $query = "UPDATE users SET Log = '$login' WHERE UserID ='$UserID'"; echo 'Previous log on was ' . $_SESSION['Log'] . '</p>'; ?> Any tips are welcome thank you (if this topic exists please redirect me to that forum!! thx)
  16. When I echo this out it returns Skoda. I think I now know where I have gone wrong here, I am attempting to pass the session data of the user into another script but requires to have a citizen watch instead of having Skoda. Ok I know what to do now Thank you Jon.
  17. Yes, this line is the only output being returned. $Man = $_SESSION['Man'];
  18. Oh no I didn't notice it I forgot to put echo there, thx I have corrected that now. BTW Jon, I have echoed out my variables but I have only managed to get the username for $Man.
  19. Hello people I am having a bit of trouble of applying the correct users to gain access to a page if they are male. For example: There are two registered users a man and a woman. The man is registered and can access another page called men's watches but not a page called women's watches and the latter applies to the opposite for women. I have written this so far, however it keeps returning the else statement even though the user is correctly logged on. <?php session_start(); $Watches = $_REQUEST['Watches']; $Female = $_SESSION['Female']; $Man = $_SESSION['Man']; if (isset($Man)) { $query = "SELECT Man, Watches FROM Male WHERE Watches = '$Watches' AND Man = '$Man'"; mysql_query($query); echo "Correct user"; <a href='watches4men.php'>Mens Watches</a> exit(); } else { echo "Not the correct user"; exit(); } ?> I hope my example is clear for you guys for your possible solutions. P.S (I have no intention of being sexist but should it offend some people I apolgise) Thank you
  20. As much and as far as possible, in other words there is no limit. Oh and thank you for your help.
  21. Hi Stuart To answer your question (and perhaps for other users as well) on what I am trying to acheive is to change the date via submit button that, when clicked is meant to go past the current date. I hope this answers your question (oh btw the next week line is just a placement, in fact I just wanted to see the output of the date). Thanks to all who so far replied.
×
×
  • Create New...