Can you give me the exact result resource error please. This will help me diagnose the issue.
Aslo you will need to post your script in [ code ] tags.
Can you give me the exact result resource error please. This will help me diagnose the issue.
Aslo you will need to post your script in [ code ] tags.
Im not too sure what you are requiring, seems to me you do not want to store data on a users computer. This is impossible (might be a black hat way around) for a person to view a webpage it must be downloaded as a whole and editing this information(deleting cache) would be violating the users rights.
OmniX is exactly right, in fact what happens is the HTML is just a page that has code in it linking files. The clients browser will take the text file and basicly turn it into an image that you see when visiting a website. So if the user doesn't download these files they can't make this image you intend for them to make.
Well you could always force a HTTP error. If thats what you mean.
Or you could always include an error page, there are many ways to do this but it's all about what will work best for you.
Well if you post your page and what the error is you're trying to give and then I could give you a solution.
I see your logic but it is somewhat floored.
If you just create a table that will hold your users details WITH AN ID!
Then you can create another table that will hold files. For instance:
file_id | owner_id | name | source | downloads
This is of course if you want to count the downloads done the source will hold the http:// source of the file, the name will be the name of the file and the file_id will be the identinfying primary key. The most important one is the owner_id, this should be the same as the users id.
Then you can run a simple query using the users id:
// The cookie holding the users username
$username = $_COOKIE['username'];
// The id from the table using thr users username to pull the row
$user_id = fetch("SELECT `owner_id` FROM `users` WHERE `username` = '$username'");
// Run the query to select all of the downloads for the specified user
$query = mysql_query("SELECT * FROM `users` WHERE `owner_id` = '$user_id'");
// Run a loops to echo out the downloads
while( $row = mysql_fetch_array( $query ) ) {
echo '<p>Name: '.$row['name'].'</p>';
echo '<p>Downloads: '.$row['downloads'].'</p>';
echo '<p><a href="download.php?dl_id='.$row['id'].'">Download the file here.</a></p>';
}
This is ofcourse only if you wish to count the downloads and try (a little bit) to hide the actual url of the file. The download.php would run similar querys to make sure the user has permition to download this file then return maybe an …
pls, help! how can i connect to mysql 5.0 database with vb6 and how do i connect to mysql database from php5.Where do i download the necessary drivers.
Not sure about VB but PHP5 should be like this:
$con = mysql_connect( "HOST ADDRESS" , "USERNAME" , "PASSWORD" );
// this is to select a database after connecting.
mysql_select_db( "DB_NAME" , $con );
Can you upload an excel file so as we know what kinda things your trying to add to mysql?
hello friendz..
jst a small query..
i made simple userinput form as userform.php....
after submit the form..values are passed to adduser.php for inserting to database... i have a serverside validation tht username cant be same...!!if(username is laready exist) { [B]header('location:userform.php?error=1');[/B]//user send back to userinput form.. } else { [B]header('location:login.php');[/B]//user logged in }
i jst want to know, is header only solution... is there any alternative to it..?? what if i dont want to send 'error=1' through url...!!! then how can i send back the error msg..???
Waiting for positive reply..!!
There's also the get method. page.php?error=2
You could also use .htaccess to hide this given error in the url so it would apear like; page.php
Well they are extremely easy to make. Do you have much PHP/MySql knowledge?
I could probably whack one out in a few hours. Of course for me to give you any ideas of how this might be done I would need to know what you have so far so as we could build around this.
Post some code and I'll see what I can do.
I have done these scripts a thousand times. I still however can't seem to sort out this issue.
The issue is that this block of code should return 3 images although it doesn't it only returns one image. The other one I am getting is from a different loop that I haven't tested yet but they are built the same way so I would presume it will do the same.
Here is my loop:
if( isset( $_COOKIE['Username'] ) && $ui['Acc_Type'] == "adm" ) {
$q = mysql_query("SELECT * FROM `galleries`") or die( "ERROR: " . mysql_error() );
while( $row = @mysql_fetch_array( $q ) ) {
$id = $row['id'];
$q = mysql_query("SELECT * FROM Images WHERE id='$id' LIMIT 1") or die( "ERROR: " . mysql_error() );
$data = mysql_fetch_array( $q );
if( $column == 0 ) {
echo '<tr>';
}
echo '<td><img src="http://localhost/pictures/gallery/'.$data['id'].'/'.$data['Src'].'" alt="'.$data['Name'].'" /></td>';
$column++;
if( $column == 4 ) {
echo '</tr>';
$column = 0;
}
$q = false;
$data = false;
$id = false;
}
}
I will attach a screenshot of the page. It is quite irritating the fact I have spent a good few hours the past two days and I have only managed to do the upload extraction and resizing, the gallery creation script, the image naming script and I have got stuck on this!
Thanks in advance.
P.S. Sorry had t zip the image it was too big for Daniweb to accept????
What type of file you are uploading, Image of Video file??? have you got solution or still looking for solution.
I am actually still having the issue I can change the settings in my ini but what I am trying to do is validate all the information about the uploaders file before they actually upload it else they spend maybe 5 minutes or so uploading the file to be told it has the wrong extension...
This is a big issue and has ground the work down to a halt.
You would just have to count the result of the rows for example when before you echo out the results (in the mysql_fetch_array) you would do this:
// count the number of entries retuned by the query
if( @mysql_num_rows( $result ) == 0 ) {
//if there isn't any give an error
die('There we no matched dates found in the database.');
} else {
//if there is echo out the results set
while( $row = mysql_fetch_array( $result ) ) {
//echo out your results...
}
}
What is the issue you are having exactly?
Do you have a server side language?
Have you read this tutorial:
http://www.phpriot.com/articles/images-in-mysql/8
The most important part is it header function that will tell the browser the mime type of the file.
I presume you mean it doesn't send to the database?
The only thing I have noticed is that the way in wich you are connecting is not the way in wich I would.
I have seen others connect this way but they were all having problems, my advice would be to stick to the w3schools method.
$con = mysql_connect( "localhost" , "root" , "" ) or die( "MySQL ERROR: " . mysql_error() );
$db = mysql_select_db( "kawempe_hc" , $con ) or die( "MySQL ERROR: " . mysql_error() );
Also as apose to addslashes I would use mysql_real_escape_string this will make sure that the database puts the data in a way that it will be able to accept it.
If the problem persist after these corrections please can you send an SQL export of your table (passwords don't need to be included) not the data just the structure.
Great so you solved the issue by mysql_real_escape ing the string?
Just for others that may come across this post.
Also would you not consider adding a timestamp as apose to a formatted date?
Try typing your query into phpMyAdmin and see if that returns any rows for the query.
It seems that the query will not return the rows due to the fact MySql will not use that format of time. It could also be that you don't have a start date that is exactly the time in wich you are unputting but I kinda thought that was obvious so you wouldn't make that mistake.
Yes probably the best way but files such as images and CSS documents JS dosument MUST MUST MUST be availbale to the public there is no way around this!
If you do however have to put them in a folder in the web root then the htaccess command "deny from all" will disallow everyone (including yourself) from viewing that folder via http, it will still be accesable via FTP.
But as I said do not put any files you link in your HTML in there PHP documents are fine because they are server side whereas your browser in my cas firefox will take those files like CSS JS and images and add it to the page.
Hmmm it sounds like a few small issues. I will have to play with it on monday as I am currently building a new PC sooo I'll see what I can do on my laptop.
For most it will probably INT or VARCHAR. I will PM you my MSN address if you like, it seems to work alot quicker in a live chat as apose to a forum thread.
Sorry I don't quite understand what you are trying to acheive.
Is it similar to linkbuks and other sites like that?
Yes when you retreive it use the date function to display it in a readable format.
Xammp & Wamp are almost identical to your web server but it wont have a DNS server thus the mail server wont work and it wont have a domain name.
Honestly I wouldn't bother, I would just download xampp and then you could do all the work locally and then just type in something like localhost/phpmyadmin and access phpmyadmin and you can just go to your browser and type in localhost/page and see the results.
As for the timestamp basicly what it does is produce a number that is the amount of seconds since 1970 so that would give you the time and date the the second.
I good peice of software that is free is Notepad++ or I have just recently bought Nusphere's PHPED that does similar to what you were describing it basicly runs the script but I don't think it would access the database.
when they next connect afetr the second day wether it be 1 second after 48 hours or 4 hours after 48 hours.
For the id because when you suto increment it will give you a one digit number wich is predictable I use a 9 digit random number so I wouldn't use auto_increment. Set it as an INT with 9 char length.
Wow thanks,
I hope what i done already is not going to be completely re done as i was proud of it lol. If so i should print it out and frame it.
Thanks so much,
genieuk
It is quite a big change but yes I'm still using your code.
I haven't tried it you will have to try it out I also added the ID field that will produce a random 9 digit id number that will not be repeated.
<?php
include("dbconnect.php");
// Change this to however many days until you need to add a new version. Defaults to 31 or a month.
$days = 31;
$ip = $_SERVER['REMOTE_ADDR'];
$host = gethostbyaddr($ip);
$agent = $_SERVER['HTTP_USER_AGENT'];
$uri = $_SERVER['REQUEST_URI'];
$ref = $_SERVER['HTTP_REFERER'];
if($ip == ""){
$ip = "None Recorded";
}
if($host == ""){
$host = "None Recorded";
}
if($agent == ""){
$agent = "None Recorded";
}
if($uri == ""){
$uri = "None Recorded";
}
if($ref == ""){
$ref = "None Recorded";
}
while( $use == false ) {
$temp = rand( 100000000 , 999999999 );
$t = mysql_query("SELECT * FROM visitordata WHERE id='$temp'");
if( @mysql_num_rows( $t ) > 0 ) {
return false;
} else {
$id = $temp;
$use = true;
}
}
$length = 60*60*24*$days;
$time = time() + $length;
$test = mysql_query("SELECT * FROM visitordata WHERE ip='$ip'");
if( @mysql_num_rows( $test ) == 0 ) {
$query = "INSERT INTO visitordata VALUES ('$id', '$time', '$ip', '$host', '$agent', '$uri', '$ref')"; //*visitordata is the name of the MySQL table where the user data will be saved.
mysql_query( $query ) or die( "MySql Error Occured: " . mysql_error() );
echo "The user data was successfully added to your database.";
} else {
$row = mysql_fetch_array( $test );
if( $row['dbtime'] <= time() ) {
$query = "INSERT INTO visitordata VALUES ('$id', '$time', '$ip', '$host', '$agent', '$uri', '$ref')"; //*visitordata is the name of the MySQL table where the user data will be saved.
mysql_query( $query ) or die( "MySql Error Occured: " . mysql_error() );
echo "The user data was successfully added to your database.";
}
}
mysql_close($conn);
?>
I suppose I learnt PHP the same way, to be honest I learned JavaScript AJAX & MySql the same way too.
I'll work on a script.
Similar just without the cookies.
I might be able to write you a script but I don't think it would help you learn.
Um no that just checks if there is a row in the mysql table that holds that IP.
To do that you would then have to add a unix timestamp to the database and work off that.
For each visitor you input you must add a unix timestamp that is 24 hours ahead of us and then you would check that if the time is less then now then you must update the values or add a new row etc.
Or you could just update the row everytime they make a move from one page to another.
Hmm I can't really think without knowing how your MySql database is structured. Can you export the database (or just the table) and post it here please. I'm not to sure why MySql would do that...
Have you looked into adding a php.ini files to get around what your host isn't allowing you to do. This solved my globals problem.
Sorry I'm lost, are you trying to refresh their data after 30 mins or making sure that it doesn't get added again.
To make sure it doesn't get added again this woul be the code:
if( $ip != "None Recorded" ) {
$test = mysql_query("SELECT * FROM visitordata WHERE ip='$ip'");
if( @mysql_num_rows( $test ) > 0 ) {
return false;
} else {
$query = "INSERT INTO visitordata VALUES ('vd_id', '$dbtime', '$ip', '$host', '$agent', 'uri', '$ref', '$oslang')"; //*visitordata is the name of the MySQL table.
mysql_query( $query ) or die( "MySql Error Occured:" . mysql_error() );
}
}
This will add them if their is not Ip recorded but will not add them if their was and it is already in the database.
You don't have to have an Id but it is an idea. Although a must is to have a primary key. I don't do much sql qith queries I tend to use phpMyAdmin. Do you have a local server?
lol you'll bemaking members scripts in no time. I'd say w3schools is probbably the best place to learn mysql but the PHP & MySql is a bit lacking try the MySql section. As for limiting char lengths I'd say limit it server side.
This way if the user input is too long it doesn't get trimmed by MySql because PHP will tell them.
I would prepose a print version of your stylesheet that will remove all content not need when printing the page.
Hello again genie :),
I will try my best to format your code...
<?php
include("dbconnect.php");
$dtime = date('F jS Y, h:iA');
$ip = $_SERVER['REMOTE_ADDR'];
$host = gethostbyaddr($ip);
$agent = $_SERVER['HTTP_USER_AGENT'];
$uri = $_SERVER['REQUEST_URI'];
$ref = $_SERVER['HTTP_REFERER'];
if($dtime == ""){
$dtime = "None Recorded";
}
if($ip == ""){
$ip = "None Recorded";
}
if($host == ""){
$host = "None Recorded";
}
if($agent == ""){
$agent = "None Recorded";
}
if($uri == ""){
$uri = "None Recorded";
}
if($ref == ""){
$ref = "None Recorded";
}
$query = "INSERT INTO visitordata VALUES ('$dbtime', '$ip', '$host', '$agent', 'uri', '$ref')"; //*visitordata is the name of the MySQL table where the user data will be saved.
mysql_query( $query ) or die( "MySql Error Occured: " . mysql_error() );
echo "The user data was successfully added to your database.";
mysql_close($conn);
?>
Ok firstly your method on adding the data ia a little out, as you may or may not know PHP does not allow quotes inside quotes unless you have the \ in fron of the contained quotes.
To solve this you ca replace the enclosed double quotes with single quotes.
The more accepted way of confirming a database query was executed properly is by using the or die statement. If there was an error it will output the error but nothing else after. However if it does execute properly it will continue to display the rest of your content.
I find spacing out your code makes it easier for you to …
Instructions are in the zip Good Luck!
That allright, I shall start them now then.
I am very flattered and I would say W3Schools is a great place to learn but also I have posted a few video tutroials on youtube under the username W3Hut so you could check them out.
Okay so lets get back to having an include file as appose to the code blocks. Create a file name global.inc, this will hold the functions needed.
In this file add the following lines of code:
<?php
function sql_con() {
$con = mysql_connect( "HOST" , "USERNAME" , "PASSWORD" );
$db = mysql_select_db( "DATABASE_NAME" , $con );
}
function returnDls( $file ) {
sql_con();
$q = mysql_query("SELECT * FROM counter WHERE file='$file'");
$array = mysql_fetch_array( $q );
echo $array['dls'];
}
?>
This file will be done and all you have to do is save it.
Now we can remove that block of code from any page that has it on including counter.php. Please make sure not to remove the sql_con(); on its own as this connects to the database.
At the top of any document that may use the functions (count.php, download page) add this one and only line @include("PATH TO GLOBAL.INC");
Please make sure also that the path to the file is the one you would use if it were on your local machine not as if it were a website.
For example on my shared server I would use @include("/home/username/public_html/global.inc");
this would then add the functions in just that line. If I was to link it …
No I always use the ' to add data. Does this fill your fields exactly? and is this the order in wich yu have to put them in? I would try:
mysql_select_db("ecommerce");
$query = "INSERT INTO products (id, item, description, price, date) VALUES (
'00001', 'toothbrush',
'Brush your teeth with this.',
395.00, '2009-21-04'),
('00002', 'tooth paste',
'You will need this too.',
695.00, '2009-21-04'),
('00003', 'mouth wash',
'Good to use after toothbrush.',
1,250.00, '2009-21-04')";
$result = mysql_query($query)
or die(mysql_error());
echo "Products added successfully!";
The extra bit I added ( (id, item ) should reflect the name of the fields in wich you are adding them to.
Another point is that you are not using your conection variable to tell MySql what server username or password to use. I understand you didn't want to post them but you must make sure that when you use the mysql_select_db function you use it like this mysql_select_db( "ecommerce" , $con );
con being your connection variable.
Also have you tried adding them individually?
mysql_select_db("ecommerce");
$query = "INSERT INTO products VALUES (
'00001', 'toothbrush',
'Brush your teeth with this.',
395.00, '2009-21-04')";
$query .= "INSERT INTO products VALUES ('00002', 'tooth paste',
'You will need this too.',
695.00, '2009-21-04')";
$query .= "INSERT INTO products VALUES ('00003', 'mouth wash', 'Good to use after toothbrush.', 1,250.00, '2009-21-04')";
$result = mysql_query($query)
or die(mysql_error());
echo "Products added successfully!";
I did also notice that where you have submitted the price you have used a comma to seperate the digits. This could …
It would seem that you will need to run a mysql_num_rows check on your query, it seems that the query is returning no matches or start dates.
echo mysql_num_rows( $q );
// $q being whatever variable you ran the mysql_query under.
Also I'm a bit un-nerved with your method. I would imagine using timestamps would make things much easier.
That way you convert the date put in to a timestamp then it would select any timestamps that are closer to the curent time because the timestamp would be a bigger number. If you catch my drift.
You should look into it, also there are functions that convert Y/M/D to a timestamp.
Ok can you use a client like phpMyAdmin to view the tables themselves?
If so do the dates indeed look like that?
What is the field name in wich the dates come under?
Have you changed the echo $row to echo $row ?
This should echo out the start dates.
Give these a try and so what you come up with.
Okay sure, here it goes.
Okay to actually display the number of time downloaded you must copy this block of code to any page you wishto display the amount of downloads:
<?php
function sql_con() {
$con = mysql_connect( "HOST" , "USERNAME" , "PASSWORD" );
$db = mysql_select_db( "DATABASE_NAME" , $con );
}
function returnDls( $file ) {
sql_con();
$q = mysql_query("SELECT * FROM counter WHERE file='$file'");
$array = mysql_fetch_array( $q );
echo $array['dls'];
}
?>
This will create the function that will retreive the number of downloads. To confirm this block must be at the top of your downloads page.
Okay so I am going to make my own downloads page that will have three downloads.
<?php
function sql_con() {
$con = mysql_connect( "HOST" , "USERNAME" , "PASSWORD" );
$db = mysql_select_db( "DATABASE_NAME" , $con );
}
function returnDls( $file ) {
sql_con();
$q = mysql_query("SELECT * FROM counter WHERE file='$file'");
$array = mysql_fetch_array( $q );
echo $array['dls'];
}
?>
<a href="code.php?file=http://example.com/example.zip">example.zip</a><br />
<p>This has been downloaded <?php echo returnDls( "http://example.com/example.zip" ); ?> times.</p>
<a href="code.php?file=http://example.com/example2.zip">example2.zip</a><br />
<p>This has been downloaded <?php echo returnDls( "http://example.com/example2.zip" ); ?> times.</p>
<a href="code.php?file=http://example.com/example3.zip">example3.zip</a><br />
<p>This has been downloaded <?php echo returnDls( "http://example.com/example3.zip" ); ?> times.</p>
This would give me:
example.zip
This has been downloaded 1 times.
example2.zip
This has been downloaded 150 times.
example3.zip
This has been downloaded 20 times.
So again …
and no you do not add it to the database the only thing that gets added is the url/location of the file relative to the directory you are calling it from so it is probably better to link the file with http:// as apose to file.zip by its self.
What happens is, when it goes to the count.php document it will take the file name and check if it is already in the database if it is then it will update the amount of dls to the new dl total ( 1 more than before ).
However if it isn't already in the table it will add the name of the file to the table and give it 1 download. So that the next time the script is run with the same file name it will be in the database and it will add one to the total of downloads.
I suppose when you learn more about PHP and MySql it will seem so much easier.
Good skills to learn.
Ok the first thing about the functions you need to put on the page that you want to display the ammount of downloads. Basicly what I am doing is creating a function that connects to the database (habbit) then I am creating a function that will ask the database how many times the file is downloaded then return how many times it has been downloaded.
As for the second part you can use either the full URL including the http://domain.com/file.zip etc. or just use the filename and extension file.zip etc.
So basicly just copy what it says to copy and then change the database information for both documents then change the link in the link tag to count.php?file=whatever your file is then click the link, this will automaticly add it to the database for you.
Very important though! the sql block must be executed in the phpmyadmin window in order fo it to access the table. If you are unsure how to do this please refer to the phpMyAdmin documentation.
If you wish I can create a video tutorial if it is really neccessary.
Yes add a link next to the table row saying edit or something like that and link it to a form with the values in a text field so you can then update or delete the entry.
Ok I haven't commented it yet but the instructions are pretty thorough so you should be able to see whats going on.
I have attached the files but I will also post them here:
INDEX.PHP
<?php
function sql_con() {
$con = mysql_connect( "HOST" , "USERNAME" , "PASSWORD" );
$db = mysql_select_db( "DATABASE_NAME" , $con );
}
function returnDls( $file ) {
sql_con();
$q = mysql_query("SELECT * FROM counter WHERE file='$file'");
$array = mysql_fetch_array( $q );
echo $array['dls'];
}
?>
<a href="count.php?file=file.zip">File</a><br />
<p>This file has been downloaded <strong><?php returnDls( "file.zip" ); ?></strong> times.</p>
COUNT.PHP
<?php
// Please enter the deatils for your MySql database into the function below.
function sql_con() {
$con = mysql_connect( "HOST" , "USERNAME" , "PASSWORD" );
$db = mysql_select_db( "DATABASE_NAME" , $con );
}
/**************INSTRUCTIONS**************/
/****************************************/
/*
Please execute the following lines in
your database query area. This would
be called sql query and can be found
on the tabs at the top when looking
at the PHPMYADMIN database view. The
following lines will add the table:
CREATE TABLE IF NOT EXISTS `counter` (
`file` varchar(500) NOT NULL,
`dls` varchar(4) NOT NULL,
PRIMARY KEY (`file`),
UNIQUE KEY `file` (`file`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
If you wish to add a new file to the
database then just add the file to
the directory of your choice and
link to this file as shown below:
count.php?file=FILENAME_PATH_AND_EXTENSION
This will add the file path, name
and extension to the database and
will redirect to the file.
To display …
<?php
// Please enter the deatils for your MySql database into the function below.
function sql_con() {
$con = mysql_connect( "HOST" , "USERNAME" , "PASSWORD" );
$db = mysql_select_db( "DATABASE_NAME" , $con );
}
/**************INSTRUCTIONS**************/
/****************************************/
/*
Please execute the following lines in
your database query area. This would
be called sql query and can be found
on the tabs at the top when looking
at the PHPMYADMIN database view. The
following lines will add the table:
CREATE TABLE IF NOT EXISTS `counter` (
`file` varchar(500) NOT NULL,
`dls` varchar(4) NOT NULL,
PRIMARY KEY (`file`),
UNIQUE KEY `file` (`file`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
If you wish to add a new file to the
database then just add the file to
the directory of your choice and
link to this file as shown below:
count.php?file=FILENAME_PATH_AND_EXTENSION
This will add the file path, name
and extension to the database and
will redirect to the file.
To display the number of views please
add this to the top of the document
you wish to display it on, you will
also need to add the details like above:
<?php
function sql_con() {
$con = mysql_connect( "HOST" , "USERNAME" , "PASSWORD" );
$db = mysql_select_db( "DATABASE_NAME" , $con );
}
function returnDls( $file ) {
sql_con();
$q = mysql_query("SELECT * FROM counter WHERE file='$file'");
$array = mysql_fetch_array( $q );
echo $array['dls'];
}
?>
To use this just add this line
were you wish to display the
the number of the downloads. For
example:
<?php returnDls( "example.zip" ); ?>
This would output JUST a number.
*/
$file = $_GET['file'];
sql_con();
$q = mysql_query("SELECT * FROM counter WHERE file='$file'");
if( @mysql_num_rows( $q ) > 0 ) {
$row = mysql_fetch_array( $q );
$updateVal = $row['dls'] + 1;
$update = mysql_query("UPDATE counter SET dls='$updateVal' WHERE file='$file'") or die( "error occured: ".mysql_error() );
} else {
$q = mysql_query("INSERT INTO counter (file, dls) VALUES ('$file', '1')");
}
echo '<meta http-equiv="refresh" content="0; URL='.$file.'" />';
?>
Sorry it is take a little longer writing up the instructions LOL ok I will add comments next to all the different things that are going on.
Ok I have read and I agree with the issue of having more than one download in any one directory. I'm sure I can create a script that uses MySql and will be able to use the one page to count all the downloads and redirect to the files. I shall start this now for you. I should be done in about 5-10mins, if you want to wait.