First off, I should say that I very nearly posted this ? in the Newbies forum, because my skills with mySQL and php are very, very new, and extremely limited, and any help anyone may be able to offer should be on that "semi-newbie" level. However this may be a somewhat advanced thing I'm trying to do, and it does involve a database, so I think this may be more appropriate.

I've created a nice form and mysql table using phpFormGenerator. It all works swell, it even accepts variables from phpNuke as hidden fields, and all data is being perfectly retrieved via those variables; checking it out via phpMyAdmin, the table and data within it also look just fine -- it works! Eureka!

What I need to do now is add a little something to the script phpFormGen made (which I customized of course) -- or rather, I suppose the addition needs to be made in the current 'process.php' in the Forms dir (the script file that creates the form, and does all the processing of data into the db and the email sent to admin).

One of the fields in this form is a drop-down box, with 4 options - they're page titles. What I want to do is to attach a URL to those page titles, depending on which they choose, so that when the admin-notify email comes to me, that field is a link (to the pertinent URL for whatever they chose). I can then add their username and pw to my htpasswd and forward that email on to them, so that they have the link for the page title they chose -- they would NOT get the link when they made the selection, of course, and I don't want those URLs in publically accessible code -- obviously they're secure, since access is only by password -- they're enormous zip files, so I sure as heck want them secure or the bw will be astronomical.

Can anyone help me out with this? I've been studying 'php fast and easy web development' as well as numerous tutorials online for roughly 12 hrs straight now, but the fact is that I just don't know enough php or how to talk to mysql with it -- I can sometimes modify existing php, and I managed to create this whole module in which this form exists, in phpNuke, but I used the "nuketools" module to do it. 😃 I'm learning fast but not fast enough! Someone please, please advise me how to make this small addition, so I don't have to do so much of this stuff manually -- those urls the page titles need to link to, being inside phpnuke's modules, are gargantuan -- almost as bad as freehost urls! 😉

Thx very very much in advance
Carmilla

    Unfortunately there is not an easy answer. If you could have the URL's public then you could simply change the values in the form. You are correct in that you need to change the process page.

    Basically what you need to do is create if/switch statements to check what the form is set to, and use that instead of what it has.

    So for instance, if they page goes through the form, and builds the body of an email piece by piece like this:
    if( blah blah blah ) { $body .= "blah blah blah"; }
    then you could do something like:
    switch($_POST['some_field'])
    {
    case "blah":
    $body.=" blah\n";
    break;

    case "boo":
    $body.=" boo\n";
    break;
    }

    It would be impossible to tell you any more without seeing the process page's code.

      Well, unfortunately, I barely understood any of your reply --
      that stuff about 'case' just leaves me blank-faced puzzled.

      However, I'm continuing to work on this problem, based
      on what limited (very!) knowledge of php I do have.

      This is the very top of the process.php in the forms dir,
      which makes the form and then processes the data it collects:

      <?php
      include("global.inc.php");
      $errors=0;
      $error="The following errors occured while processing your form input.<ul>";
      pt_register('POST','Username');
      pt_register('POST','Email');
      pt_register('POST','MainURL');
      pt_register('POST','SetDesired');
      pt_register('POST','Password');
      pt_register('POST','AgreeTerms');
      if($Username=="" || $Email=="" || $MainURL=="" || $SetDesired=="" || $Password=="" || $AgreeTerms=="" ){
      $errors=1;
      $error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
      }
      

      Now, my hypothetical solution would be to add some stuff
      just below the include(global.inc.php)
      (before any processing actually takes place!),
      like this:

      <?php
      include("global.inc.php");
      
      /* my addition starts here  */
      
      $set01url = "http://www.thefullurl/tothe1st/zipfile.zip";
      $set02url = "http://www.thefullurl/tothe2nd/zipfile.zip";
      $set03url = "http://www.thefullurl/tothe3rd/zipfile.zip";
      $set04url = "http://www.thefullurl/tothe4th/zipfile.zip";
      
      global $set01url, $set02url, $set03url, $set04url;
      if ($SetDesired == "Set 01") {
      	$SetDesired == $set01url;
      }
      elseif ($SetDesired == "Set 02") {
      	$SetDesired == $set02url;
      }
      elseif ($SetDesired == "Set 03") {
      	$SetDesired == $set03url;
      }
      else ($SetDesired == "Set 04") {
      	$SetDesired == $set04url;
      }
      
      /* my addition ends, the file continues */
      
      $errors=0;
      $error="The following errors occured while processing your form input.<ul>";
       ...blah blah...
      

      Do you think this would work? and/or, is there anything
      wrong with the syntax, punctuation, etc?

      I checked online by entering the actual url for the
      process.php, and it's not accessible, it yields that
      error msg about empty fields, so those urls should
      be safe enough. I haven't tried it out yet, I thought
      I would pop in here and see if anyone had anything
      to say about it. It seems kludgy; I had thought it
      would need to do something with an array, but I don't
      know the first thing about making an array, filling an
      array, or what to do with it once you have it. argh!

      Any comments on my proposed solution? (I figured it
      was workable to simply replace the contents of
      $SetDesired with the actual urls, since in most
      email clients, full urls become links anyway).

      Thx much!
      Carmilla

        You have the right idea. What you did was basically the same thing I was demonstrating. switch() is a handy function for easily testing a var against several options. In this instance, you can use switch() to check what $setDesired is set to. It does the same thing as your series of if() statements, but is cleaner. If you are more comfortable using if(), then go ahead. There is nothing wrong with it.

        As far as the code, you shouldn't need to global your vars:
        "global $set01url, $set02url, $set03url, $set04url;"

          Well, it didn't work. I finally managed to make it stop giving a parse error on the line with the 'else' statement, and it appeared to process normally. But, looking in the database itself, all the "SetDesired" fields are still showing "Set 0X" rather than the url I tried to substitute into that field. boohoo and all that, all that head-bashing for nothing.

          Also it may have broken the email function, since none of the admin mails I should have received from my tests has arrived, though that might of course just be my host being slow to process 'em. (but the longer I wait, and keep polling, and keep receiving nothing, the more it looks like the email function is broken.)

          So I'm brokenhearted, and have no earthly idea what to do. Oh yes, I did save my old process.php before meddling with it, so I can always fix it back, but that just puts me back to square 1, doesn't fix the initial problem I was aiming at.

          :mad: 😕 :mad:
          Carmi

            If you post the entire page, it might help.

              Well, it was my understanding from reading the various policies and FAQs that the
              admin sorta frowned on that, I think it says something about that, in one of
              those guidelines. But if you think it will help, I guess the page isn't too long.

              First off, though, couple of things, and a question. (it would be just plain lazy of
              me to simply dump this problem here and expect someone to solve it for me,
              plus I wouldn't learn much, if I don't make the effort to try and solve it myself,
              hopefully with some help from some of you folks that know a lot more php than
              I do).

              1) I resolved the email problem; it wasn't the script, but a hairball with my host;
              fixed now (checked both with a test msg from a diff domain, and from a test-
              submission using a clean-unmodified process.php -- the email does now get
              sent and received).

              2) After fixing it back to the clean-unmodified version, I tried it again with my
              addition, but this time making those url variables global. Still doesn't work,
              with or without the global. (perhaps I should clarify, it works precisely as the
              unmodified process.php works -- it writes to the db and does the email, but still
              with the original value of $SetDesired, so my addition is the part not working).

              And finally my question, probably a very stupid question but since I know so little of
              how variables are handled, I must ask it, simply for my own clarification.

              In the bits

              if ($SetDesired == "Set 01") {
              	$SetDesired == $set01url;
              }

              Since the '$set01url' is referring to a string (the actual url), should it have quotes
              around it, even though it's a variable?

              And also: is there some better way of getting the new string into the $SetDesired
              variable, than those '==' operators? The only other programming I ever learned
              anything about (and that wasn't much!) was Basic, and this sort of thing would
              work, but of course this is very far from Basic of any flavor.

              Ok that's it for my input at this point; I'm still stymied, can't figure out why I can't get
              those urls into the $SetDesired variable. So here goes with the long-winded php.

              This is the original, unmodified process.php, which works perfectly in all respects:

              <?php
              include("global.inc.php");
              $errors=0;
              $error="The following errors occured while processing your form input.<ul>";
              pt_register('POST','Username');
              pt_register('POST','Email');
              pt_register('POST','MainURL');
              pt_register('POST','SetDesired');
              pt_register('POST','Password');
              pt_register('POST','AgreeTerms');
              if($Username=="" || $Email=="" || $MainURL=="" || $SetDesired=="" || $Password=="" || $AgreeTerms=="" ){
              $errors=1;
              $error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
              }
              if($errors==1) echo $error;
              else{
              $where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
              $message="Username: ".$Username."
              Email: ".$Email."
              MainURL: ".$MainURL."
              SetDesired: ".$SetDesired."
              Password: ".$Password."
              AgreeTerms: ".$AgreeTerms."
              ";
              $message = stripslashes($message);
              mail("address@mydomain.net","Form Submitted at your website",$message,"From: phpFormGenerator");
              $link = mysql_connect("localhost","dbuser","password");
              mysql_select_db("freecontentusers",$link);
              $query="insert into contentusers (Username,Email,MainURL,SetDesired,Password,AgreeTerms) values ('".$Username."','".$Email."','".$MainURL."','".$SetDesired."','".$Password."','".$AgreeTerms."')";
              mysql_query($query);
              $make=fopen("admin/data.dat","a");
              $to_put="";
              $to_put .= $Username."|".$Email."|".$MainURL."|".$SetDesired."|".$Password."|".$AgreeTerms."
              ";
              fwrite($make,$to_put);
              header("Refresh: 0;url=http://www.mydomain.net/redirectthanks.html");
              }
              ?>

              Here it is with my changes; I've left out the globals thing since you said I didn't
              need it, and it didn't work any better with it -- notice that I also changed the final
              bit, for set04url, since that was the line causing a parse error when I initially
              tried it:

              <?php
              include("global.inc.php");
              
              
              $set01url = "http://www.actualurl/of1st/zipfile.zip";
              $set02url = "http://www.actualurl/of2nd/zipfile.zip";
              $set03url = "http://www.actualurl/of3rd/zipfile.zip";
              $set04url = "http://www.actualurl/of4th/zipfile.zip";
              
              if ($SetDesired == "Set 01") {
              	$SetDesired == $set01url;
              }
              elseif ($SetDesired == "Set 02") {
              	$SetDesired == $set02url;
              }
              elseif ($SetDesired == "Set 03") {
              	$SetDesired == $set03url;
              }
              else  {
              	$SetDesired == $set04url;
              }
              
              $errors=0;
              $error="The following errors occured while processing your form input.<ul>";
              pt_register('POST','Username');
              pt_register('POST','Email');
              pt_register('POST','MainURL');
              pt_register('POST','SetDesired');
              pt_register('POST','Password');
              pt_register('POST','AgreeTerms');
              if($Username=="" || $Email=="" || $MainURL=="" || $SetDesired=="" || $Password=="" || $AgreeTerms=="" ){
              $errors=1;
              $error.="<li>You did not enter one or more of the required fields. Please go back and try again.";
              }
              if($errors==1) echo $error;
              else{
              $where_form_is="http".($HTTP_SERVER_VARS["HTTPS"]=="on"?"s":"")."://".$SERVER_NAME.strrev(strstr(strrev($PHP_SELF),"/"));
              $message="Username: ".$Username."
              Email: ".$Email."
              MainURL: ".$MainURL."
              SetDesired: ".$SetDesired."
              Password: ".$Password."
              AgreeTerms: ".$AgreeTerms."
              ";
              $message = stripslashes($message);
              mail("address@mydomain.net","Form Submitted at your website",$message,"From: phpFormGenerator");
              $link = mysql_connect("localhost","dbuser","password");
              mysql_select_db("freecontentusers",$link);
              $query="insert into contentusers (Username,Email,MainURL,SetDesired,Password,AgreeTerms) values ('".$Username."','".$Email."','".$MainURL."','".$SetDesired."','".$Password."','".$AgreeTerms."')";
              mysql_query($query);
              $make=fopen("admin/data.dat","a");
              $to_put="";
              $to_put .= $Username."|".$Email."|".$MainURL."|".$SetDesired."|".$Password."|".$AgreeTerms."
              ";
              fwrite($make,$to_put);
              header("Refresh: 0;url=http://www.mydomain.net/redirectthanks.html");
              }
              ?>

              That's it. I'm going to keep reading and bashing away at it, but really I'm totally
              perplexed at this point, so I hope you can make something more of it than I can.

              Oh and one other question: would it be helpful to see that global.inc.php
              that's included at the top of process.php? And (just for the heck of asking) do
              you think it might work better if I included my additions there, instead of in
              process.php? (that way, process.php would never see the original value of
              $SetDesired)

              Thx very much!
              Carmi

                OK, I didn't read the whole thing because I realized that I made a foolish mistake.

                == is a comparison, meanging "is equal to"
                where as = actually assigns a value. Your if() should be like this:

                if ($SetDesired == "Set 01") {
                $SetDesired = $set01url;
                }

                Some how I missed that. Change the == to = like it is above and see if it fixes it.

                As far as the quotes around string, you only need quotes around actual strings. If the item is a number, or a variable representing a sting, then you don't need to worry about it.

                Post again if that doesn't work, and I'll look at the code. I bet that this will solve the whole problem though.

                  It still didn't work.

                  I also tried it with the == changed to = as you pointed out, and included the
                  'global' thing, and that didn't work either. I also went into my phpform/forms/admin
                  dir and removed all data accrued from all these tests, just in case that was somehow
                  messing it up. I guess it wasn't; it had no effect either.

                  So I'm positively baffled. :mad: 😕 :mad:

                  Carmi :eek:

                    Write a Reply...