PHP need help badly!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mi3x
Forum Newbie
Posts: 13
Joined: Fri Mar 06, 2009 8:52 am

PHP need help badly!

Post by mi3x »

Hello, the problem is that I don't know exactly what to look for, that's why I write in a forum, asking for help.
Basically, I have a site (static html), and what I would like to do with php help is the following. Every time I need to create a new "transaction number info page" html file for a customer (e.g. FS4234FGS.html), I do it offline with the help of a HTML editor, I replace the info (name, address, information about product, etc), save it as a new transaction number file (eg SSFFD242.html) and reupload it on the site, and give the customer the name of this file, so he can access it on my site, by entering it in a field, which checks if the file is available and redirect the customer to it.

I would like if possible to cut the time spent of doing this and to be able to create this kind of new files directly on my website, to be like accessing a http://www.mysite.com/neworder.php kind of a file which after filling some forms would create a new file with a given name, keeping the template of the html file, and replacing only the data that needs to be replaced (like $fname, $lname etc).

I guess you kind of understand my wish, can that be possibly done with php? If you don't have the time to explain, can you at least point me in to right direction, what EXACTLY kind of script do I need to look for?

Thank you very very much. :oops:
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: PHP need help badly!

Post by susrisha »

Hello,
I beleive what you are looking for is something like this:

1. Some fields of information about the customer
2. These fields to be stored and written to a html file.(the name of which i guess has to be random)
3. The uploaded link of the file to be sent to your customer.

If you are insistent on this design here is my solution.
1. You need to use a form page to get the details of the customer.
2. You can use php script to write the contents into a html page (naming can also be done).
3. Once the information is written into the file, it has to be moved to the folder you wish to.
4. Since php has the location of the file, it can be displayed as a hyperlink on the screen.
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: PHP need help badly!

Post by susrisha »

Have created two files that might help you

This is how your html code might look like

Code: Select all

 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>Insert title here</title></head><body><form action="mi3xscript.php" method="post"><table><tr><td>Detail1</td><td><input type="text" name="Detail1"/></td></tr><tr><td>Detail2</td><td><input type="text" name="Detail2"/></td></tr><tr><td>Detail3</td><td><input type="text" name="Detail3"/></td></tr><tr><td>Detail4</td><td><input type="text" name="Detail4"/></td></tr><tr><td>Detail5</td><td><input type="text" name="Detail5"/></td></tr></table> </form> </body></html> 
This is how your php code might be like

Code: Select all

 
<?php
$upload_dir="./files/"; //change this to the directory where you want to put the files.
 
 
/*function generate_random_string
  generates a random string of given length and for a given seed
*/
function generate_random_string($length,$seed=123)
{
$randPWD1 = '';
srand((double)microtime()*1000000);
for($i=0;$i<$length;$i++)
{
    $n = rand(48,120);
    while (($n >= 58 && $n <= 64) || ($n >= 91 && $n <= 96))
    {
        $n = rand(48,120);
    }
    $randPWD1 .= chr($n);
}
 
$randPWD1 = $randPWD1.time().$seed;
$randPWD = strtolower($randPWD1);
 
$randPWD = md5($randPWD1);
$randPWD = substr($randPWD,0,$length);
return $randPWD;
} //end of function generate_random_strin
 
$file_name=generate_random_string(8,122);
$file_path =$upload_dir.$file_name.'.html';
//get all the posted values here
 
$detail1=$_POST['Detail1'];
$detail2=$_POST['Detail2'];
$detail3=$_POST['Detail3'];
$detail4=$_POST['Detail4'];
$detail5=$_POST['Detail5'];
//$detail1=$_POST['Detail1'];
 
//open the file in write mode
$fh = fopen($file_path,"w");
//write all the variable details into the file
fwrite($fh,$detail1 );
fwrite($fh,$detail2 );
fwrite($fh,$detail3 );
fwrite($fh,$detail4 );
fwrite($fh,$detail5 );
fclose($fh);
 
//show the page details to the customer
echo "Your information has been stored as $file_name";
echo "<a href=\"$file_path\">Click Here to see</a>";
?>
 
mi3x
Forum Newbie
Posts: 13
Joined: Fri Mar 06, 2009 8:52 am

Re: PHP need help badly!

Post by mi3x »

susrisha wrote:Hello,
I beleive what you are looking for is something like this:

1. Some fields of information about the customer
2. These fields to be stored and written to a html file.(the name of which i guess has to be random)
3. The uploaded link of the file to be sent to your customer.

If you are insistent on this design here is my solution.
1. You need to use a form page to get the details of the customer.
2. You can use php script to write the contents into a html page (naming can also be done).
3. Once the information is written into the file, it has to be moved to the folder you wish to.
4. Since php has the location of the file, it can be displayed as a hyperlink on the screen.

Thank you susrisha for replying so fast!
Now, you mainly got my point. The customer first will register, so all the info is already available to me.
1 and 2 is correct. No 3. doesn't necessary needs the link to be sent to the customer, just to be uploaded automatically, so I can contact the customer and pass the "customer number" to him.

For the design, I already have this template of the transaction number, but the question still remains, what kind of a php script should I look for to do this job for me?

Shortly, the script should help when I navigate to it to my site, to give me a simple form with fileds like:

First name: -
L name -
Registration date -
Address -
Item -
ETC.

This data is already available to me, so after filling it, a new randomly html file to be generated and available to my site (transaction number) , with my given template.

So, I looked to hotscripts but I don't know for what script to look for. Thanks again sorry for my english, I'm not a native speaker. :oops:
mi3x
Forum Newbie
Posts: 13
Joined: Fri Mar 06, 2009 8:52 am

Re: PHP need help badly!

Post by mi3x »

Thanksss, will try the script locally to see how it works and post feedback. I'm new once again, but I thank you so much for your help. BRB with my feedback.
mi3x
Forum Newbie
Posts: 13
Joined: Fri Mar 06, 2009 8:52 am

Re: PHP need help badly!

Post by mi3x »

OMG, it actually works!!!!!!!! I added a submit button and...voila!!!!! THANk YOU!

I have a few more requests for modifications if you can help, I really don't know what to modify even though you gave me the starting point.

1. I would like the newly created html file to begin with : ZG + numbers + letters + the first 3 letters in the name of "last name" of the customer - that I fill in in the first html file. (12 character transaction number, only uppercase)
2. Can you tell me how can I insert my own html template in the output? Because now, it only writes a new html file, containing only the data inserted, without any other information (my template).

That would be all, if there is somehow I could reward you, if you have a project or something you develop, a few dollars to donate would be my pleasure!

THANKS!
mi3x
Forum Newbie
Posts: 13
Joined: Fri Mar 06, 2009 8:52 am

Re: PHP need help badly!

Post by mi3x »

Ok, I managed with some help to solve the problem with the random number, still I have a problem.

How can I comment the data from $outputdata = "<html>...etc</html>" so that it wouldn't give me T_string errors? Because inside that html body I have some other scripts, java etc, and every " or ' is seen as an end to the outputdata, and the color of the text changes from red to black, blue, and to that line it gives me the error. Here is an example:

Code: Select all

$outputdata = "<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
 
 
  <title>&deg;&deg; $monsit -  Espace Client $fname $lname &deg;&deg;</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
 
  <meta http-equiv="imagetoolbar" content="no">
 
  <style type="text/css">
<!--
.sf_aereo {
background-image: url("../image/cake.jpg");
background-repeat: no-repeat;
background-position: right top;
}
 
-->
 
....etc"


Can somebody help me so it wouldn't give me errors? Should I transform all the html to php? Like this?

Code: Select all

$outputdata = "echo "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n";
 
echo "<html>\n";
 
echo "<head>\n";
 
echo "  \n";
 
echo "  \n";
 
echo "  <title>&deg;&deg; $monsit -  Espace Client $lname &deg;&deg;</title>\n";
 
echo "  <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\">\n";"
Thanks! :roll:
mi3x
Forum Newbie
Posts: 13
Joined: Fri Mar 06, 2009 8:52 am

Re: PHP need help badly!

Post by mi3x »

Finally worked it out! Thanks alot, I used heredocs syntax, it works! Thank you!!!!!!!!!!!!!

Solved, thanks everyone, thanks devnetwork!
mi3x
Forum Newbie
Posts: 13
Joined: Fri Mar 06, 2009 8:52 am

Re: PHP need help badly!

Post by mi3x »

As you helped me creating my script to upload automatically new transaction number, I once again ask for help with a code snippet. I didn't open another thread, so here is the code within a html page.

Code: Select all

<script language="JavaScript">function PasswordLogin()
{ document.location.href = document.formlogin.trackingnr.value + ".html";
return false;
}
function CheckEnter(event)
{
var NS4 = (document.layers) ? true : false;
var code = 0;
if (NS4)
code = event.which;
else
code = event.keyCode;
if (code==13)
{ PasswordLogin();
event.returnValue = false;
}
}</script>
It works well, but I don't know what to modify in order to search the document in another folder. For example, now it only searches the document entered only in the folder where the script (which is in a html page), and I would like it to look for the document in a folder let's say "transactions" which is down one level, or up one level. What should I modify? Can you help please? Thanks
mi3x
Forum Newbie
Posts: 13
Joined: Fri Mar 06, 2009 8:52 am

Re: PHP need help badly!

Post by mi3x »

Heredocs works very well, and as I didn't get any errors, I think I will stick with it. As for the javascript, I am sorry I posted a wrong script.

Here is the script I wanted to post:

Code: Select all

<script type="text/javascript">
 
function PasswordLogin()
{
    var filename = document.formlogin.trackingnr.value.toUpperCase() + ".html";
    var http = window.XMLHttpRequest
        ? new XMLHttpRequest()
        : new ActiveXObject('MSXML2.XMLHTTP.3.0');  
 
    if (!http)
    {
        window.location = filename;
        return false;
    }   
 
    http.open('GET', filename, true);
    http.onreadystatechange = function()
    {
        if (http.readyState == 4)
        {
            if (http.status == 200)
            {
                window.location = filename;
            }
            else
            {
                alert('Votre Numero est errone. Merci de reessayer!');
                return false;
            }
        }
    }
    http.send(null);    
    return false;
}
 
 
                          </script>

Any Ideas on how to change the search location?

Here is the form:

Code: Select all

<form action="" method="get" name="formlogin" onSubmit="return PasswordLogin();">
                                    
Numero de Depistage:
                                              <p>
                                                <input name="trackingnr" id="trackingnr" size="14" type="text" class="style112" onBlur="this.value = this.value || this.defaultValue; this.style.color = '#999';" 
onFocus="this.value=''; this.style.color = '#000';">
                                                <br>
                                                <input name="button" value="Suivi!" type="submit" style="background: #FF6600; color: white; font: 8pt bold Verdana, Arial, Helvetica, sans-serif">

Thanks!
mi3x
Forum Newbie
Posts: 13
Joined: Fri Mar 06, 2009 8:52 am

Re: PHP need help badly!

Post by mi3x »

merci beaucoup, mais ... and now in English, as it's an English forum :)

I got it how to put it one level up, but the fact is that the folder I want this script to look in, its in another level down. I guess "/.." doesn't work :)
I would like to specify a given folder... still searching for an anwser.

Merci de m'en tenir au courant! :wink:


LE: Nobody can figure this out? :banghead:
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: PHP need help badly!

Post by susrisha »

Code: Select all

 
var filename = "./yourfolder/" + document.formlogin.trackingnr.value.toUpperCase() + ".html";
 
 
mi3x
Forum Newbie
Posts: 13
Joined: Fri Mar 06, 2009 8:52 am

Re: PHP need help badly!

Post by mi3x »

Susrisha, thanks once again! I had the code all the time under my nose, you gave me earlier :)

All the best to you, thanks again for everything, I managed to achieve today with your help mostly what I had in mind for months!! :drunk: :drunk:
Post Reply