Page 1 of 2 12 LastLast
Results 1 to 15 of 28

Thread: PHP question

  1. #1
    Resident Cannibal
    Join Date
    Nov 2007
    Location
    The Internets
    Posts
    4,692
    Thanks
    7
    Thanked 21 Times in 12 Posts
    Rep Power
    0

    Default PHP question

    I've been asked to make a website which allows the following;

    Person adds their details to the website on form 1 (a distributor)
    A folder is created with the id number which the distributor has entered
    A standard form (form 2) is copied to the new folder which needs to be sent to the distributors email address on sumission

    So far I have made form 1 which adds distributor id, name, and email address to a SQL database.

    I need to get the page to create the folder using the distributor id, copy form 2 over, and change the email address to match that in the database.

    Any ideas guys? My php skills arent the best tbh.

  2. #2
    Not to be trusted with your Jaffa Smifis's Avatar
    Join Date
    May 2010
    Location
    Great Yarmouth, Norfolk
    Posts
    5,327
    Thanks
    918
    Thanked 438 Times in 384 Posts
    Rep Power
    2

    Default

    If I understand you correctly, I wouldn't go at it like that.

    So somebody enters a distributors detail in one form, then the info gets put into the database, then you make a folder that corresponds to the ID of the Distributor.

    A link to the 2nd form is sent via email to the distributor.

    Am i correct with this?


  3. #3
    Resident Cannibal
    Join Date
    Nov 2007
    Location
    The Internets
    Posts
    4,692
    Thanks
    7
    Thanked 21 Times in 12 Posts
    Rep Power
    0

    Default

    Basically what we need to do is for each individual distributor to enter their details on to a database so that a folder is created with their number, once this is done the website automatically creates a directory with another form which prospective distributors fill in, the response to which is emailed to the original distributor. There may be 1000s of distributors so it's not feasable to do this manually.

    Hope thats a bit clearer

  4. #4
    Rhys's Avatar
    Join Date
    May 2010
    Posts
    530
    Thanks
    30
    Thanked 53 Times in 32 Posts
    Rep Power
    1

    Default

    right well...

    Not delved into fopen, fclose etc sorta stuff for php but i get the jist of what you want.

    fopen/close/etc all use the servers power to make,edit,delete files. like an FTP client but you do it through php pages, so you could in all honesty make an FTP client on a webserver.
    Its useful for editing web pages etc but can be unsecure since your leaving open free connections to your server but its the only way i know off.

    Now to do it:

    on the page where it submits to the SQL server.

    add the lines
    PHP Code:
    $file fopen(/$distributerid'w');
    fclose($file
    below the mysql_query() bit but where the variables that have been sent from the form are still useable.

    i believe that should make a file which then you can use to send to the person though the mail() function.

    if it dont work ill give it a try on my home server and see what the problem is or if theres any other way.

    so yeah.
    get back to me if it works or dont

    ill work on a way to copy files etc. if not ill see if theres a way to create the file with preset data
    HTML || CSS || PHP || MYSQL
    Will Code For Cookies

  5. #5
    Resident Cannibal
    Join Date
    Nov 2007
    Location
    The Internets
    Posts
    4,692
    Thanks
    7
    Thanked 21 Times in 12 Posts
    Rep Power
    0

    Default

    Will give it a shot

  6. #6
    Not to be trusted with your Jaffa Smifis's Avatar
    Join Date
    May 2010
    Location
    Great Yarmouth, Norfolk
    Posts
    5,327
    Thanks
    918
    Thanked 438 Times in 384 Posts
    Rep Power
    2

    Default

    Would it not be better to have a single file?

    index.php?action=add_dist
    index.php?action=view_dist&dist_id=xxxx
    index.php?action=del_dist
    index.php?action=dist_form&dist_id=xxxx

    So like the, the database is actually storing the info and not using a folder structure


  7. #7
    Rhys's Avatar
    Join Date
    May 2010
    Posts
    530
    Thanks
    30
    Thanked 53 Times in 32 Posts
    Rep Power
    1

    Default

    that is reasonable but without proper security ?.... can easily be hacked.

    and to do proper security it would mean a load more coding.

    I cant see someone messing with the folders if they dont know theyre structure or whos got one while if they use the 1 file it can all go pear shaped (no offence to Mr Pear).

    but its what Jon's asking for anyways so yeah.
    HTML || CSS || PHP || MYSQL
    Will Code For Cookies

  8. The Following User Says Thank You to Rhys For This Useful Post:


  9. #8
    Not to be trusted with your Jaffa Smifis's Avatar
    Join Date
    May 2010
    Location
    Great Yarmouth, Norfolk
    Posts
    5,327
    Thanks
    918
    Thanked 438 Times in 384 Posts
    Rep Power
    2

    Default

    Yh, that was just an example, on certian pages you'd need login boxes, passwords etc. wouldn't be too hard to do IMO


  10. #9
    Resident Cannibal
    Join Date
    Nov 2007
    Location
    The Internets
    Posts
    4,692
    Thanks
    7
    Thanked 21 Times in 12 Posts
    Rep Power
    0

    Default

    Just messing with it at the moment, once its working I can add bits and peices.

    I'm having a problem at the moment where the page where it adds the distributor to the database is saying that there is an undefined variable

    Here is the code, theres bits in there I'm not using as I've just copied it from another site and changed bits to match;

    <?php
    $con = mysql_connect("localhost","database","class66");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("distributors", $con);

    $sql="INSERT INTO distributors (distributornumber, firstname, email)
    VALUES
    ('$_POST[distributornumber]','$_POST[firstname]','$_POST[email]')";

    if (!mysql_query($sql,$con))
    {
    die('Error: ' . mysql_error());

    }

    print("$distributornumber<br>");
    if (!is_dir($distributornumber))
    {
    // create the directory and put the file into this directory;
    $oldumask=umask(0);
    mkdir($distributornumber, 0777) or die ("Could not make directory");
    umask($oldumask);
    chdir($distributornumber);
    ////////copy ($file, "$file_name");
    print("\$distributornumber - $distributornumber after mkdir <br>\$file_name -
    $file_name<br>");
    }
    else
    {
    // put the file into this directory;
    chdir($distributornumber);
    //////////copy ($file, "$file_name");
    print("\$distributornumber Just the copying - $distributornumber<br>\$file_name -
    $file_name<br>");
    }
    print("\$distributornumber - $distributornumber<br>");
    echo "1 record added";
    //////////////$file = fopen("/$distributornumber", "w");
    ///////////////fclose($file);

    mysql_close($con)

    ?>

  11. #10
    Not to be trusted with your Jaffa Smifis's Avatar
    Join Date
    May 2010
    Location
    Great Yarmouth, Norfolk
    Posts
    5,327
    Thanks
    918
    Thanked 438 Times in 384 Posts
    Rep Power
    2

    Default

    Do you have msn?


  12. The Following User Says Thank You to Smifis For This Useful Post:


  13. #11
    Resident Cannibal
    Join Date
    Nov 2007
    Location
    The Internets
    Posts
    4,692
    Thanks
    7
    Thanked 21 Times in 12 Posts
    Rep Power
    0

    Default

    yup, woady66(@)hotmail(.)com

  14. #12
    Rhys's Avatar
    Join Date
    May 2010
    Posts
    530
    Thanks
    30
    Thanked 53 Times in 32 Posts
    Rep Power
    1

    Default

    fixed the problem with the variables.

    he just didnt write em out lol.

    now for the fopen stuff ;D
    HTML || CSS || PHP || MYSQL
    Will Code For Cookies

  15. #13
    Not to be trusted with your Jaffa Smifis's Avatar
    Join Date
    May 2010
    Location
    Great Yarmouth, Norfolk
    Posts
    5,327
    Thanks
    918
    Thanked 438 Times in 384 Posts
    Rep Power
    2

    Default

    I'd be tempted to scrap the folder idea. depending on server permissions and such using fopen my not even be feasible


  16. #14
    Rhys's Avatar
    Join Date
    May 2010
    Posts
    530
    Thanks
    30
    Thanked 53 Times in 32 Posts
    Rep Power
    1

    Default

    fopen works on all linux servers.
    even shared ones.
    its a preset PHP function so its preinstalled.

    could say flash should be scrapped for its lack of security but they dont because it works.
    HTML || CSS || PHP || MYSQL
    Will Code For Cookies

  17. #15
    Not to be trusted with your Jaffa Smifis's Avatar
    Join Date
    May 2010
    Location
    Great Yarmouth, Norfolk
    Posts
    5,327
    Thanks
    918
    Thanked 438 Times in 384 Posts
    Rep Power
    2

    Default

    Indeed...I hate flash websites.


Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •