No
Yes it would actually be easier with a MySql database. The reason for not being able to open the counter text is because your host has probably denied access to open and read external files (files linked with the http://) so just make sure in the download page you also link to it by just putting the counter.txt name.
Ok so I will rewrite the script and give you a SQL snippet for you to add to your new table.
Have you changed the download page $file attribute this should be the counter on the file.
It's 3:05am in the morning why are you still up :P I have an excuse I work nights haha.
Ok try again remove the counter. CHMOD the PHP download counter document to the highest you can. Then go to the download page (where the counter is) and click the download link to download the file. When you go to the countdownloads.php page it should give some errors, then go back to the index page with the download link. It should say 1 now then go through and test it again this time there should be no errors.
It might be that you have to put the directory releative to the current working directory. I have tested the script on a working Windows server.
If it is in the releative directory (current working directory) then you could just add counter.txt and download.zip or whatever the download file is.
You might also want to try adding counter.file for your counter file.
Delete the counter file and just add it to the directory without chmoding it.
Oh yes if you can't be bothered to create the file then just go through the download process once, it will turn up errors about it not existing but then it will create the file.
Actually I'll rewrite it.
In the countdownloads.php replace it for this:
<?php
$file = "DOWNLOAD NAME INC DIRECTORY";
$counter = "COUNTER NAME INC DIRECTORY";
//Don't edit below this line
$prevNum = file_get_contents( $counter );
$newNum = $prevNum + 1;
$handle = fopen( $counter , "w" ) or die( "Issue opening the counting file, please chmod the counter file named ".$counter );
fwrite( $handle , $newNum );
fclose( $handle );
echo '<p>Download should start shortly...</p>';
echo '<meta http-equiv="refresh" content="0; URL='.$file.'" />';
?>
Ok that will make the script smaller but acheive the same thing. Next change the lines for echoing out the number to this:
<p><a href="countdownloads.php">Download File</a><br />
<?php
$file = "COUNTER NAME INC DIRECTORY";
$downloads = file_get_contents( $file );
echo $downloads;
?> Downloads<br />
since Feb 2008</p>
Off the cuff as I have heard people say, so it might not work I'll test it now.
Try to make sure the file is in the current directory. Also an easier method of getting a files contents would be to use the get contents method: $theData = file_get_contents( "counter.txt" );
Thats it.
Thanks for the replies, from what I can gather PHP uploads the file to a temporary directory before running the first line of the script anyhow. Is there a way I can safely validate the file before PHP uploads it to a temp directory.
Also from what I gather the accept attribute isn't trustworthy as only a small percentage of browsers even register this attribute as being there.
Ok the issue from what I can see is the way in wich you are connecting to the database.
Try this method:
$con = mysql_connect( "SERVER" , "USERNAME" , "PASSWORD" )
or die( "Could not connect: " . mysql_error() );
$db = mysql_select_db( "DATABASE" , $con );
This should work and also give you any errors whilst connecting to the database. Please note before making the site live please remove the or die statement.
Ok so where the loop is (while( $row = mysql_ ) you need to change the array's to the names of each field on the rows of your table.
HTML FILE:
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Bookings Details </title>
</head>
<body>
<p>Enter the client and Booking date below to chek bookings information </p>
<form action="../actions/bookings_details.php" method="post">
<p><label for="D M Y">Booking Date:</label><br />
<input id="D M Y" name="D M Y" type="text" /></p>
<p><input type="submit" value="Check Booking" /></p>
</form>
</body>
</html>
PHP FILE:
<html>
<head>
<title>Bookings Details</title>
</head>
<body>
<?php
$con = mysql_connect("xxxxxx","xxxxxxx","xxxxxx");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("xxxxxxxx", $con);
$date = $_POST['D M Y'];
$q = mysql_query( "SELECT * FROM bookings WHERE startdate='$date'" );
while( $row = mysql_fetch_array( $q ) ) {
echo $row['date']."<br />";
echo $row['availbale']."<br />";
}
mysql_close($con);
?>
</body>
</html>
Try this out and see what you get.
The main problem was you wasn't executing the query correctly and you weren't asking PHP to echo out the results set.
Hi
I will explain what I am trying to do:
I have used MYPHP admin to create a database where user booking details will be stored in a table called bookings.
Now I need to retrieve all the bookings for a specific date. For achieving this I have created two pages one is html page for user to type the date and click on get bookings and the second page is a php page where it will have the database connection and the MySQL query.
But it only returns a blank page. Below are my html and php pages code.
Any help will be highly appreciated
Kind Regards
HB25
Html page<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Bookings Details </title> </head> <body> <p>Enter the client and Booking date below to chek bookings information </p> <form action="../actions/bookings_details.php" method="post"> <p><label for="date">Booking Date:</label><br /> <input id="%D %M %Y" name="%D %M %Y" type="text" /></p> <p><input type="submit" value="check Booking" /></p> </form> </body> </html>
PHP page
<html> <head> <title>Bookings Details</title> </head> <body> <?php $con = mysql_connect("xxxxxx","xxxxxxx","xxxxxx"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("xxxxxxxx", $con); SELECT * FROM bookings WHERE startdate=$_POST[%D %M %Y]; mysql_close($con); ?> </body> </html
You didn't seem to actually make the query in the PHP document.
Where you wrote
mysql_select_db("xxxxxxxx", $con);
SELECT * FROM bookings WHERE startdate=$_POST[%D %M %Y];
mysql_close($con);
you need to actually send the query. For example what you would do is
$date = $_POST[%D %M %Y];
$query …
Hi, it's a pretty straightforward gallery http://www.siiimple.com/
Would each image have to have it's own folder, therefore it's own directory?
I guess the idea is to count the number of times a visitor clicks on an image - to visit that particular site. I would display the total just below the image.
Thanks very much for your help. I'm learning php (albeit, slowly).
Unless you do something like taking the filename of the image and removing the extension (.jpg, .png etc.) and peplacing it with a .txt version. This would mean for every image you have you will have the same amount of text files. I have to say it would be allot easier implementing some sort of PHP/MySql/AJAX/JavaScript system.
Hi!
I want to know that how can i use buttons to update ( edit or delete) records from the php form directly into the database...
Thanks
Ok what you are trying to do it edit a table right...
If you want to display the row in the form for them to update or delete then I would advise this...
Create the form and echo the contents out.
Make sure you either have the id displayed in a text box or you have it in a hidden field.
You will need to submit buttons with two different values ( Update , Delete ) they should also have the same name and that should be it for the form.
When it gets to the document handling the request (the action on the form) we need to do something similar to this.
<?php
if( isset( $_POST['Update'] ) ) {
// Run your update query
} elseif( isset( $_POST['Delete'] ) ) {
// Delete from query
}
?>
That would be how you structure the document. If you are unclear in any way on how to update or delete rows in a MySql table then please refer to the W3Schools tutorials.
Hello all
i have (after much googleing) written a php script which when activated appends to a main text file with the text seen below in this exact formattype=
name=----------------------------------------------------------------------------------------------
#
type=
name=(USER INPUT HERE)
#
type=
name=----------------------------------------------------------------------------------------------
#what i need is a simple webform with one input field where the user can enter thier name.
When they hit submit the main text file would be written (appended) to with the text shown above yet with the users name in place of (USER INPUT HERE).From what i understand this is a 3 part job and i am missing the first two parts the input and processing of the data
i have found many simple input forms but have no clue how these should be made to work with my present script which works the way it should.Can some one point me in the right direction?
im going through all the tutorials i can at the moment and might find a solution before anyone here can help.
But there is no harm in asking .ciao folk
thanks for any feedback
solocky
You need to first open the file: $handle = fopen( "FILEPATH" , "a" ); // a meaning amend
Then you need to fwrite the file with the users input:
fwrite( "#\ntype=\nname=".$_POST['input'] , $handle );
Then close the file: fclose( $handle );
This should work.
Are these three seperate documents? If os the post values will only be passed onto the document you secify in the action attribute of your form after you move from this page the post data is destroyed.
If you need to move the data from the second page to the third try using the get method (will have ?pid=playerid in your title) or if you want it to be more professional create a cookie and then call it when you are on your third document.
Please make sure that when adding headers you clear the line:
$headers = "From: ".$from_address."\r\n";
Take note on the \r\n part.
I thought he was using dates in the past so it wouldn't work the same... Maybe not.
Ok this is a working result:
$timeStamp = strtotime( "1986-11-02" , time() );
echo date( "M. j, Y" , $timeStamp );
Try this:
strtotime( "1986-11-02" , time() );
If that is a DATETIME field type, you can use UNIX_TIMESTAMP() like this
SELECT UNIX_TIMESTAMP(`date`) FROM `my_table`
then use date() to show it correctly
No if you were to add the UNIX timestamp to the database as a UNIX timestamp then you could use the array from the database like this:
echo date( "M. j, Y" , $databaseArray );
This would work if you used the PHP time function when putting the date in the database. Although there is a format you can use that PHP can convert to a timestamp then you can use the date function like I just did.
I will look at it some more. :-)
I've checked this through and there is an error or two the one I can remember is the date at the top was classed as an integer and it needs to be a string.
So this is the working script:
<?php
$date = "1986-11-02";
//We need to seperate the different parts YYYY-MM-DD
//We use the explode method for this we need to eplode the - chars
//So we need to create a variable holding our explode function
$parts = explode( "-" , $date );
//Now we should have the following
// $parts[0] = 1986
// $parts[1] = 08
// $parts[2] = 02
// Now we create a case statement for each of the months!
switch( $parts[1] ) {
case 01:
$parts[1] = "Jan";
break;
case 02:
$parts[1] = "Feb";
break;
case 03:
$parts[1] = "Mar";
break;
case 04:
$parts[1] = "Apr";
break;
case 05:
$parts[1] = "May";
break;
case 06:
$parts[1] = "Jun";
break;
case 07:
$parts[1] = "Jul";
break;
case 08:
$parts[1] = "Aug";
break;
case 09:
$parts[1] = "Sep";
break;
case 10:
$parts[1] = "Oct";
break;
case 11:
$parts[1] = "Nov";
break;
case 12:
$parts[1] = "Dec";
break;
}
$parts[2] = str_replace( 0 , false , $parts[2] );
//Ok so now our $parts[1] (the month) is in the text format we can peice it back together
$newDate = $parts[1].". ".$parts[2].", ".$parts[0];
echo $date." is now ".$newDate;
?>
I have been trying to format a date that I receive from a value in a mysql database. The format in mysql is as follows.
1986-08-02
I want to convert that toAug. 2, 1986
I tried the date function in php and it was not working for me. Anyone, have any ideas how I can do this.
Thanks,Alex
Is it possable to change the way in wich you add the dates to the database as keeping them in UNIX timestamps makes the whole date thing much much easier and better yet allows you to do more to it.
Ok if this isn't possable then you want to look into the explode function and the case statements as this will make up most of the function you need to make.
This should put you on the right track.
<?php
$date = 1986-08-02;
//We need to seperate the different parts YYYY-MM-DD
//We use the explode method for this we need to eplode the - chars
//So we need to create a variable holding our explode function
$parts = explode( "-" , $date );
//Now we should have the following
echo $parts[0] // 1986
echo $parts[1] // 08
echo $parts[2] // 02
// Now we create a case statement for each of the months!
switch( $parts[1] ) {
case 01:
$parts[1] = "Jan";
break;
case 02:
$parts[1] = "Feb";
break;
case 03:
$parts[1] = "Mar";
break;
case 04:
$parts[1] = "Apr";
break;
case 05:
$parts[1] …
I'm not 100% sure but it usually means one of the following
- The file does not exist
- The file does not have the correct permissions (chmod[linux/unix]/Read Only[windows/dos])
- MySql doesn't have permission to open, edit or create the file
Any of the listed can cause this. As I said though I can't be 100% sure. Try looking into these permissions and see what you come up with.
Thanks for the reply and sorry for the slow come back.
Ok so how does that make sure that the file is not larger than 60MB what scripting is behind this?
Also is there any way of validation the extension before upload?
Thanks again.
Hello,
I have been working on some scripts for a forthcoming site and I have run across an issue. The issue being that when uploading large files (60Mb + ) will only be validated after they have finished being uploaded to a temporary directory. As you could probably imagine this is quite an issue.
Is there somesort of way I can validate the file before it has finished uploading. If so how is this acheived?
I have searched google and till now have found nothing and it is becoming quite tedious.
Thanks in advance for any help given.
why are you using javascript at all in the login process? I mean, only use it for basic validation not hashing. That in itself is a security flaw because attackers can see how you are encrypting a password, which helps them to crack it.
What if a user has javascript turned off? Then what. You should have php handle everything.
I agree JavaScript is more efficient (for the users) but PHP should always be your focus as it is loaded before the hacker gets the page.
Always make sure with important scripts that you make sure that the refering URL is the the page you wish it to come from.
Do you have access to any server-side scripting(PHP, ASP, JSP) etc.?
If so you can configure a script to count all the times the image is viewed.
Else you may need to use a thrid party site to count it for you. Others with web servers may do this for you usually free of charge, of course if you ask nicely. There are many popular sites on the web that offer this service for free.
If you do have access to a server-side script then I maybe able to help you. I only have knowledge in PHP.
Didn't realise this was in the PHP forum. Ok the PHP code would go a little like this.
<?php
$filePath = "PATH TO TEXT FILE THAT WILL HOLD VISITS";
$current = file_get_contents( $filePath );
$current = $current + 1;
$fileHandle = fopen( $filePath , "w" );
fwrite( $fileHandle , $current );
fclose( $fileHandle );
echo "Visits: ".$current."<br />";
?>
Ok the only issue is that you will only be able to use this if each image has its own directory. The next thing you could do is implement JavaScript to submit the information via AJAX to the PHP document that controls the text files. Or you could even use databases.
Please give me more on how your gallery works.
Do you have access to any server-side scripting(PHP, ASP, JSP) etc.?
If so you can configure a script to count all the times the image is viewed.
Else you may need to use a thrid party site to count it for you. Others with web servers may do this for you usually free of charge, of course if you ask nicely. There are many popular sites on the web that offer this service for free.
If you do have access to a server-side script then I maybe able to help you. I only have knowledge in PHP.