adam.adamski.96155 43 Junior Poster

Ahhh okay :)
The replacement value would be
""
(empty quoted string).

adam.adamski.96155 43 Junior Poster

You need to use a while loop:

while ($row = mysql_fetch_assoc($result)){
    //echo your HTML
}

http://uk1.php.net/manual/en/function.mysql-fetch-assoc.php

adam.adamski.96155 43 Junior Poster

What if you use your friend's details on the PC that works for you?
What if your friend uses your details on his machine?
What if your friend changes his $_GET['dir'] variable to 'mottram' in the URL?
Did you create the upload directory manually or let the script create it?
What if you delete your upload directory (/mottram/) and upload the image again, does it work okay?

adam.adamski.96155 43 Junior Poster

PHP scripts are not compiled, they are interpreted (parsed) by the webserver on the fly as and when the script is called by the broswer.
If you want the PHP in the text file to be parsed (what you would call compiled), then you can use - include() or require() and the extension of the file is irrelevant.
It seems that none of the filesystem functions will parse the PHP code in the file whatever the extension is (.php or .txt)

adam.adamski.96155 43 Junior Poster
adam.adamski.96155 43 Junior Poster

If the file that is being 'got' by file_get_contents() has the extension '.txt' will the server parse the file as PHP?
Change '.txt' to '.php' and see if it helps.
If you want to keep the extension as .txt, and still have the file parsed by the server, you could use the include() directive.

adam.adamski.96155 43 Junior Poster

I tested your code on my local windows machine:

$file = "testFile.txt";
$fh = fopen($file, 'a+') or die("can't open file");
$firstname = "firstName"; $lastname = "lastName"; $mood = "mood";
$datestring = date("d/m/y ");
$timestring = date("H.i.s");
$data   = "$firstname ; $lastname ; $mood ; $datestring : $timestring\r\n" ;
$data  .= "$firstname ; $lastname ; $mood ; $datestring : $timestring\r\n" ;
fwrite($fh, $data);
fclose($fh);

and it printed:

firstName ; lastName ; mood ; 19/10/12  : 12.00.35
firstName ; lastName ; mood ; 19/10/12  : 12.00.35

to the testFile.txt
I also tested it on my remote unix based host and it gave exactly the same result. Maybe I can see all the code concerned?

adam.adamski.96155 43 Junior Poster

Look here:
http://www.php.net/manual/en/ref.filesystem.php
specifically fopen()

adam.adamski.96155 43 Junior Poster
$data = "$firstname ; $lastname ; $mood ; $datestring : $timestring\r\n";
adam.adamski.96155 43 Junior Poster

That's great!
Are we solved then... are we, are we?
:D

adam.adamski.96155 43 Junior Poster

It isn't right, you need to take the path out of the encodeURIComponent() function and just encode the filename.

adam.adamski.96155 43 Junior Poster
  1. I did a search on google for "offer file for download".
  2. I checked the third result
  3. I found the answer:

    content = "abc123";
    document.location = "data:text/octet-stream," + encodeURIComponent(content);
    
  4. I tested it:

        function download(){
        content = "image.jpg.jpg";
        document.location = "data:text/octet-stream," + encodeURIComponent(content);
        }
    

and...

<a href="javascript:;" onclick="download(); return false;">click</a>

...it worked, offering me the file for download.

[edited to fix code format.]

adam.adamski.96155 43 Junior Poster

If the browser is navigating to a pdf file, it will probably try to open it with the browser plug-in unless the browser's own config tells it to pass the file to the system default application. If you offer the browser the file for download, I imagine the user will get the opportunity to open the file with their system default program or do whatever they want with it.

adam.adamski.96155 43 Junior Poster

Hey, I liked the challenge, so I tried it out.

//in the head section: This function makes the text input elements depending on the number selected in the options.

<script type="text/javascript">
function makeInputs(amt){
    var str="";
    for(i=0;i<amt;i++){
        str += 
        "<input type=\"text\" name=\"text_" + 
        (i+1) + "\"" + 
        " id=\"text_" + i + "\"" +
        " value=\"\" />\n";
    }
    document.getElementById('inputs').innerHTML = str;
}
</script>

//in the body, this makes the select area on the page, also there is a div in which to show the text inputs when they are made.

<select style="width:160px;" id="text" name="participants" required="required">
<option id="" value="" name="">-Select participant-</option> 
<script type="text/javascript">
for(i=0;i<30;i++){
    document.write(
    "<option id=\"opt_" + i + 
    "\" value=\"" + i + 
    "\" name=\"opt_" + (i+1) + 
    "\" onclick=\"makeInputs(" + (i+1) + ")\">" + (i+1) + 
    "</option>\n");
}
</script>
</select>
<div id="inputs">
</div>

Hope this helps, any more questions let us know.

adam.adamski.96155 43 Junior Poster

Your code looks good to me, I have read it all through and can't see any mistakes. I replicated your list of checkboxes and ran it and it works fine, returning an array because you named the elements with [] (unlike the poster above). How are you testing the value of zaznaczenie_email[] ? Did you try the "get" method for the form, are all the variables in the URL?

adam.adamski.96155 43 Junior Poster

PHP is not like Javascript, it is parsed by the server before the script is loaded in the browser. Once the page is loaded, PHP is finished until the next script load. If you want PHP to do anything in response to user input/action, you need to collect data using forms and reload the page (submit the form) with the PHP code ready to respond. Another option is to use Javascript to send a HTTP request to a PHP page mimicing the behaviour of a form being submitted (in the background), and again using Javascript to deal with the PHP response.
http://www.php.net/manual/en/tutorial.forms.php

adam.adamski.96155 43 Junior Poster

I would highly recommend sanitising the data before input, using an if test to check $_POST exists before any DB operations, taking the post vars and assigning to new variables. I don't think '$_POST[key]' is going to parse correctly either:

$name = mysql_real_escape_string(trim($_POST['name']));
$address = mysql_real_escape_string(trim($_POST['address']));
$sql = "INSERT INTO mytable (name, address) VALUES ('$name', '$address')";

or:

    $sql = "INSERT INTO mytable (name, address) VALUES ('".$_POST['name'])."', '".$_POST['address']."')";

Also, check the folder that contains the files for an error-log as nothing is going to the screen.

adam.adamski.96155 43 Junior Poster

Hey, great job!
It's good to be part of a success story :D

adam.adamski.96155 43 Junior Poster

If you click on one of the topics in this forum and start to type a response, and then try to navigate away from the page using the browser's back button, a javascript alert pops up verifying that you want to leave the page or stay on the page. Maybe post in the javascript forum asking how this function is acheived.

adam.adamski.96155 43 Junior Poster

So the new row is inserted before the page is built, and PHP writes the result (success/failure) to a hidden form element. Use <body onload=""> to activate a javascript fucntion that shows the image for desired amount of time.
Or use ajax to insert data via a separate php file and show the message on return of the ajax response.

adam.adamski.96155 43 Junior Poster

I copied your code into my own page and ran it and got a result with FF, IE and Chrome:

object(SimpleXMLElement)#1 (1) {
  [0]=>
  string(5) "52.82"
}

Strange...

adam.adamski.96155 43 Junior Poster

If there is only one input or drop box how will their be more than one file to merge?
You could use a multi-select element:
http://www.w3schools.com/tags/att_select_multiple.asp
The drag and drop looked good, was lightweight to code and I don't see a problem with 25 pdfs :)

adam.adamski.96155 43 Junior Poster

It means that for each search for love that exploded in our faces, there is love searching for each of us.

adam.adamski.96155 43 Junior Poster
adam.adamski.96155 43 Junior Poster

On line 75 the action of the form is malformed.
You have duplicate id's on the list elements.
When the form is submitted, you need to check the variables exist and are in the correct format before you use the merge function.

adam.adamski.96155 43 Junior Poster

Ok, I don't know if I can help but posting the code can only help. I can see from the error 'Could not locate PDF on ''', and addPDF('', 'all') that the pdf to add variable is not assigned.

adam.adamski.96155 43 Junior Poster

Ok, but both IF statements have the same OR clause (!== ''). Which, if evaluates to TRUE will mean your other condition (!isset) isn't tested.

adam.adamski.96155 43 Junior Poster

After line 55 ($string_exp = "/^[A-Za-z .'-]+$/";), put $number_exp = "/^[0-9]+$/";
On line 71 change (!preg_match($string_exp,$age)) to (!preg_match($number_exp,$age))
The age was being validated as a string.

adam.adamski.96155 43 Junior Poster

How are you stumped? What did you try?
If you use a select menu for the choosing of the .pdfs to be merged, and a submitted form to carry the choices to a processing function it's relatively simple.
You need to use javascript for the drag and drop, and to update the form variables before posting, it's certainly more complicated.

adam.adamski.96155 43 Junior Poster

I wrapped your code in an ajax function, and made the xml file, and it alerted Ben on all three browsers (IE, FF, Chrome) - http://www.zigstum.com/randoquote/dani.php
Do you have no error console to debug javascript?

adam.adamski.96155 43 Junior Poster

Nice one!
Ahhh, I have a warm glowy feeling inside :D

adam.adamski.96155 43 Junior Poster

It's possible using Javascript.
Add the onblur event to the text box and attach it to a function that replicates the textbox value in the textarea.

adam.adamski.96155 43 Junior Poster

the Email don't go at all to the users

Does this mean that no users ever get an email? Or does it mean that not all users get a mail, but some users get a mail?

adam.adamski.96155 43 Junior Poster

Hey again :)
line 119:
action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>
PHP parses the variable $_SERVER['PHP_SELF'] and echoes the current URL as the action, so whatever you name the file, the correct URL will be in the action declaration.
Now you want that to stay the same, but to add some more text to it also (it's called concatenation where you extend a string).

$string = "this" . " is"  . " a " . "string";
echo $string; //outputs "this is a string"

So you need to concatenate $_SERVER['PHP_SELF'] and "?ID=" and $_GET['ID']
Look here for some more info on concatenation - http://webdesignertutorials.com/tutorials/concatenating-php-strings.html and post back if you have any more problems.
Good luck! :D

adam.adamski.96155 43 Junior Poster

Sorry if I am patronising, but are you sure your server supports short tags (line 120)?
<?= "blah blah" ?> won't work on some servers,
<?php echo "blah blah"; ?> works on all.
Can we see the page?

adam.adamski.96155 43 Junior Poster

Hey again :)
First, good job with the pages showing your testing!
You send the variable via the URL so it must be retrieved via the $_GET array on the test.php page. This works fine with the link you have at the bottom of the page because the &name=value pair is certainly passed in the link. However, when the form is submitted using the submit button the $_GET variable is not available. This is because the &name=value pair is not in the url.
So how does the form page know know where to redirect to when it is submitted? Because the URL is in the action declaration of the form - action="/test.php". So if you want to take a variable from the url, you could add it to the action - action="/test.php?foo=bar", which will acheive the desired effect.
The problem is that you are declaring the variable on the outer page (presumably index.php), and then trying to collect that variable in delete.php, this will never work because the variable was never available to the page delete.php with the submit button.
Hope this helps, let us know how you get on.

adam.adamski.96155 43 Junior Poster
adam.adamski.96155 43 Junior Poster
adam.adamski.96155 43 Junior Poster

php might be involved but to display something on page for a few seconds is a task for javascript so maybe you need to start this thread in that forum to get the best chance of a relevant and timely answer i also recommend using punctuation in your post as if you are too lazy or impatient to explain your problem clearly you are also probably too lazy and impatient to write your code properly and it will be a painful thing to help you
http://www.englishclub.com/writing/punctuation.htm

adam.adamski.96155 43 Junior Poster

Hey that's great! Be aware that $_GET is a global by default, so you could reference it in your function, also you could have passed the variable to the function (prefered method) -

function delete($file){//everytime you want function to access variable... 
    if (unlink($file)){//it must referenced by the variable in the function declaration - ($file).
    //do functionary things
    }
}

and call the function with the variable passed:

$filename = $_GET['filename'];//define $filename
delete($filename);//send $filename to function.

You could also have passed $_GET['filename'] to the function -

delete($_GET['filename']);

Well done :D

bradly.spicer commented: Helpful :) +0
adam.adamski.96155 43 Junior Poster

Line 124 tells the script to die before showing the form.

adam.adamski.96155 43 Junior Poster

Are you sure no variable is included in the name? In my gmail it hides the email address from me and only shows me the name of the sender. What if you hard code the from address, does it show then? What mail class are you using? Can you point us to the website?

adam.adamski.96155 43 Junior Poster

You have discovered variable scope:
http://www.homeandlearn.co.uk/php/php8p2.html
http://www.w3schools.com/php/php_variables.asp
See if you can work it out, let me know if you get stuck :)
Good luck!

adam.adamski.96155 43 Junior Poster

There are two methods available with a HTML form, "get" and "post". If the form is using get method, the variables will be in the $_GET array for PHP to use, but they will also be in the URL in &name=value pairs. If the form is "post" method, the variables will be in the $_POST array and not in the URL.

adam.adamski.96155 43 Junior Poster

It stopped putting your variables into the URL when you changed from get to post. Have a look at the code that declares $filename, the problem is clear :D

adam.adamski.96155 43 Junior Poster

Haha, good to see you still at it :D
This one problem is simple, you added a 'get' method to the form, yet I told you to echo 'post', you can either change the form method to post, or the variable to $_GET.

adam.adamski.96155 43 Junior Poster

You can search google for 'beginner PHP tutorial'.
The first result is the 'simple tutorial' on php.net website.
If that is too hard, you need to grow your brain :D
Good luck!

adam.adamski.96155 43 Junior Poster

Index.php - fix your HTML tags, you close the page before you open it. You haven't named your select element and won't be able to access the selected file. Your form has no method.
Delete.php looks ok, but fix index before you worry about it.
You should write print_r($_POST); die(); at the top of delete.php and don't remove it until you see the filename as you want it to be sent to the function.

You need to learn how to build a form in HTML, then how to grab the data entered using PHP. This is the bread and milk of PHP, there are multitudes of tutorials online.
Good luck! :D

adam.adamski.96155 43 Junior Poster

Is it possible that the script you are using has a place to add valid recipients as an attempt to stop somebody using your form as a mailshot device? The error could mean that the script has received the email address and it is not malformed, but that it is not on the list of valid recipients. The only other thing I can think is that method requires your input to be quoted - "<$_GET['ID']>", but that would be unusual I think. You could kill the script in the class itself - echo $_GET['ID'] on the first line of the AddToAddr() and see what the value is. Maybe if you post the contents of the class that contains the method we an see more.

adam.adamski.96155 43 Junior Poster

Hmm, that's interesting :D
I'm sure there are better ways, but I would log the user's IP Address and browser agent on login either in a DB, a session variable or in a separate text file, and every time they try to perform an action, check to see if they are already logged on, and if so check that they are using a different browser. However, this is a PHP minded solution, and your page is all Ajax, so maybe a more suitable answer will be found in the ajax forum. Good luck!