DeeDee
-
Posts
26 -
Joined
-
Last visited
Posts posted by DeeDee
-
-
Perhaps I never understand well what you wanted to do, but this seems unnecessary. Nevertheless, good work!
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
-
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.
-
What exactly do you want to do? Do you have extire text files stored as blobs in the database? If that's the case, just echo the appropriate information that is grabbed from the database. Otherwise, you'll need to use functions like fread() to actually read external text files, and display the content on the screen.
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.
-
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
-
This is from the manual
// It will be called downloaded.pdf header('Content-Disposition: attachment; filename="downloaded.pdf"');
Your line doesn't seem to be terminated properly.
So basically your $_GET request is failing? it loks to me?
Have you tried echoing out the $_GET['id];, what does it return?
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
-
<?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) { // if it num_rows = 1 } else { // if not } mysql_free_result($result); } else { // error } ?>
First of, it seem you have one to many brackets in your code, after the $result if. Sorry. Just edited out some code before looking at it...
From php.net: Mysql_query()
For Select(...) mysql_query() returns a [b]resource on success[/b], or [b]FALSE on error[/b].
I don't know if
if ($result)
will work then. Maybe you should do
if ($result !== false) {}
instead? I don't know if this is the problem.
I have tried it, still does not work. Thanks though it is appriciated.
-
No, what response is it returning when you run it.
Which else statement??
And are you sure this line is correct
header("Content-Disposition: attachment; name =" . $row['name']);
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.
-
What exactly is it returning?
Also here:
$query = "SELECT name, type, size, Content FROM Files WHERE id = '$id'";
You don't need to quote the $id as its an integer not a string
It should return the contents of the file and prompt you with a download.
-
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(); ?>
-
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.
-
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!!)
-
DeeDee,
Like HartleySan, I just tested this as well and it`s working perfectly!
Sorry, I wrote my reply late last night and looking at your code again I realize that you actually were attempting
a "timestamp" in the database, so my apologies for the confusion. However, I think I got confused because you
put the "NOW()" function call in a variable:
I`m sure this is perfectly fine, but I think doing that is completely unnecessary.
As HartleySan said, something like the following (which is the code I used) should work fine:
$q = "UPDATE users SET last_login=now() WHERE user_id={$_SESSION['user_id']} LIMIT 1";
Make sure you have a field in the database set as follows:
last_login DATETIME NOT NULL
Hope this helps!
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
-
DeeDee,
I would not suggest grabbing the last login time this way:
The best way to do this is with a timestamp in the database!
If you grab the date/time from the user`s machine, then it will depend on the user`s location/time zone.
Since many of your visitors will certainly come from different parts of the world, this will cause you to lose
a precise point of reference If you use a timestamp, then all dates/times will be entered relative to one
time zone (i.e. GMT or wherever your server is located)!
Hope this helps!
Matt
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.
-
Don't have the means to verify this at the moment, but try the following:
Replace the following:
$login = 'NOW()'; $query = "UPDATE users SET Log = '$login' WHERE UserID ='$UserID'";
With this:
$query = "UPDATE users SET Log = NOW() WHERE UserID ='$UserID'";
I think the usage of the single quotation marks (which interpret everything literally (i.e., not as functions, etc.) is screwing things up.
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.
-
Hello, Im not quite at the section in the book on sessions and and not able to read php well yet
so am probably totally wrong but wouldn't you need and include for mysqli connect?
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.
-
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)
-
Ok so your setting
$_SESSION['Man']
somewhere prior to this script.
What does
$_REQUEST['Watches']
return?
What should it return?
And how are you passing the data to this script?
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.
-
-
what username variable?
$Man is blank right?
Is the page you posted where your setting the $_SESSION['Man'];
Yes, this line is the only output being returned.
$Man = $_SESSION['Man'];
-
DeeDee,
First try echoing out your variables I think you'll find them empty
So you need to look at how to set the session variable
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.
-
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
-
Great Ill check that out Larry, thanks so much!!
-
Still unsure as to what dates you want to output (how many? how far in the future?) but the code below is the basic principal:
<?php if ($_SERVER['REQUEST_METHOD'] == 'POST'){ for ($i = 1; $i < 11; $i++){ $timestamp = time() + ($i * 24 * 60 * 60); echo '<p>' . date('Y-m-d', $timestamp) . '</p>'; } } ?> <form method="post"> <input type="submit" name="submit" value="Update" /> </form>
As much and as far as possible, in other words there is no limit. Oh and thank you for your help.
-
Hi DeeDee,
With regards the second part - what exactly are you trying to achieve?
The code as it stands:
<html> <head> </head> <body> <?php $submit = $_POST['submit']; if($submit){ for ($i = 40; $i < 100; $i++) { $i = time() + ($i * 24 * 60 * 60); } } echo 'Next Week: ' . date('Y-m-d', $i) . "\n"; ?> <form> <input type="submit" name="submit" value="update"/> </form> </body> </html>
- You have no method set in your form tag meaning it will default to GET rather than POST
- The echo statement is outside of the loop meaning it will only echo the next week line once
- 100 * 24 * 60 * 60 will be 100 days away not next week
- You can't redefine $i inside the loop else when it executes a second time it wont have the correct value
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.
- You have no method set in your form tag meaning it will default to GET rather than POST
Downloading Files
in PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition)
Posted
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
dataA.php
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