90 users online (0 members and 90 guests)  


  Results 1 to 10 of 10

Related

  1. Replies: 2
  2. Replies: 0
  3. Replies: 2
  4. Insert a wav file    Forum: HTML Forum
    Replies: 3
  5. Replies: 2
  1. #1
    jej1216's Avatar
    New User

    Status
    Offline
    Join Date
    Sep 2008
    Location
    Albuquerque, NM
    Posts
    5

    Question SUBMIT - can it insert to DB and create a txt file?

    I have a form written in PHP and HTML. When the user clicks SUBMIT, the data entered is inserted into a MySQL DB - that part works fine.

    I also need to code it so a unique file is created as well. The filename will be created based on the valus of 2 fields on the form, and it will be an empty txt file. The reason for this is that our Sys Admin has a system of automated email notifications that will route notification to a person based on the filename.

    Can one SUBMIT perform both the db insert and the file-create? If so, how? If not, what other options do I need to look at?

    TIA,
    jej1216

  2. #2
    jthayne's Avatar

    Status
    Offline
    Join Date
    Aug 2008
    Location
    Texas
    Posts
    508

    Re: SUBMIT - can it insert to DB and create a txt file?

    The way to make it work is to add lines on the same page that submits the data to the database. Just add the lines there. PHP can process as much as you want when you want it to. Your submit is not limited to only one task.

    You will want to use the following functions: fopen, fwrite, and fclose.

  3. #3
    jej1216's Avatar
    New User

    Status
    Offline
    Join Date
    Sep 2008
    Location
    Albuquerque, NM
    Posts
    5

    Re: SUBMIT - can it insert to DB and create a txt file?

    Thanks,

    I figured out that I was being too nearsighted - I was trying to force an action into just the submit function of the form page. I figured out to put it in the php page that does the update - as you suggest.

    I do get a warning, but the data gets into the DB and the file gets created, so I'm 99% there.

    Thanks,

    jej1216

  4. #4
    jthayne's Avatar

    Status
    Offline
    Join Date
    Aug 2008
    Location
    Texas
    Posts
    508

    Re: SUBMIT - can it insert to DB and create a txt file?

    What is the warning you get? I can help you figure out what the problem is there.

  5. #5
    jej1216's Avatar
    New User

    Status
    Offline
    Join Date
    Sep 2008
    Location
    Albuquerque, NM
    Posts
    5

    Re: SUBMIT - can it insert to DB and create a txt file?

    Thanks -

    The message I get:
    Warning: fclose(): supplied argument is not a valid stream resource in /usr/local/php_classes/incidents/ir_updall.php on line 156

    line 156 on the offending PHP page:

    PHP Code:
    $sevvar substr("$_REQUEST[severity]"5, -22);

    if (
    $sevvar>"2") {
      
    $file "notify/$sevvar".".$_REQUEST[fac_id]".".txt";

      
    $handle fopen($file'w');
      
    fclose($file);                     <------------------- line 156
      
    }
    else
    {
      echo 
    "";
      } 
    The file gets created - so it works - not sure what is causing the warning though.

    TIA,

    jej1216
    Last edited by jej1216; 09-09-2008 at 10:34 AM. Reason: omitted some information before

  6. #6
    jthayne's Avatar

    Status
    Offline
    Join Date
    Aug 2008
    Location
    Texas
    Posts
    508

    Re: SUBMIT - can it insert to DB and create a txt file?

    You need to close the handle, not the file.

  7. #7
    jej1216's Avatar
    New User

    Status
    Offline
    Join Date
    Sep 2008
    Location
    Albuquerque, NM
    Posts
    5

    Re: SUBMIT - can it insert to DB and create a txt file?

    Thanks so much - that did it.

    Slowly but surely learning PHP............

  8. #8
    jthayne's Avatar

    Status
    Offline
    Join Date
    Aug 2008
    Location
    Texas
    Posts
    508

    Re: SUBMIT - can it insert to DB and create a txt file?

    Just keep plugging away, and you will get it.

  9. #9
    Maldrex's Avatar
    New User

    Status
    Offline
    Join Date
    Dec 2008
    Posts
    8

    Re: SUBMIT - can it insert to DB and create a txt file?

    Quote Originally Posted by jej1216 View Post
    Thanks -

    The message I get:
    Warning: fclose(): supplied argument is not a valid stream resource in /usr/local/php_classes/incidents/ir_updall.php on line 156

    line 156 on the offending PHP page:

    PHP Code:
    $sevvar substr("$_REQUEST[severity]"5, -22);

    if (
    $sevvar>"2") {
      
    $file "notify/$sevvar".".$_REQUEST[fac_id]".".txt";

      
    $handle fopen($file'w');
      
    fclose($file);                     <------------------- line 156
      
    }
    else
    {
      echo 
    "";
      } 
    The file gets created - so it works - not sure what is causing the warning though.

    TIA,

    jej1216
    Use this:

    $sevvar = substr($_REQUEST['severity'], 5, -22);

    if ($sevvar>"2") {
    $file = "notify/".$sevvar.".".$_REQUEST['fac_id'].".txt";

  10. #10
    jthayne's Avatar

    Status
    Offline
    Join Date
    Aug 2008
    Location
    Texas
    Posts
    508

    Re: SUBMIT - can it insert to DB and create a txt file?

    Quote Originally Posted by Maldrex View Post
    Use this:

    $sevvar = substr($_REQUEST['severity'], 5, -22);

    if ($sevvar>"2") {
    $file = "notify/".$sevvar.".".$_REQUEST['fac_id'].".txt";
    Not sure what it is you are trying to do with that code. A little explanation would be good since the original problem was taken care of.



Tags for this Thread