Okay folks, lets beat this dead horse a little harder, because i'm not getting it...

I am attempting to post to the following website:

http://www.eslteachersboard.com/cgi-bin/esljobs/index.pl?form=0

Which, for those of you who don't want to view the page source, it has the following form:

<FORM ENCTYPE="multipart/form-data" METHOD=POST  ACTION="http://www.eslteachersboard.com/cgi-bin/esljobs/index.pl?post" NAME="message" TARGET="_self">

<INPUT TYPE=TEXT NAME="name" SIZE=40 MAXLENGTH=100>
<INPUT TYPE=TEXT NAME="email" SIZE=40 MAXLENGTH=100>
<INPUT ....> // A FEW MORE OF THESE TYPE

//ONE OF THE FOLLOWING TYPE
<TEXTAREA COLS=80 ROWS=20 NAME="body" WRAP=VIRTUAL></TEXTAREA>

//A COUPLE OF THE FOLLOWING
<INPUT TYPE=SUBMIT NAME="Preview" VALUE="Preview your Job Offer">
&nbsp;
<INPUT TYPE=SUBMIT NAME="Post" VALUE="Post your Job Offer">

//AND THATS ALL!
</FORM>

What I am attempting to do, is to post to this form/website with data from my website.

I am trying to do this with the following code:

<?php

...

$query="SELECT * FROM mark WHERE jobid = $jobid";
$result=mysql_query($query);  

printf("Job Preview:");
echo "<br>--------------------------------<br>";
$id=mysql_result($result,$i,"jobid");
$name=mysql_result($result,$i,"company");
$email=mysql_result($result,$i,"email");
$location=mysql_result($result, $i, location");
$desc=mysql_result($result,$i,"description");
$url=mysql_result($result,$i, "url");

echo "<br>$id<br>$name<br>$email<br>$location<br>$desc<br>$url<br>";

/* Post data to website */

$ch = curl_init();
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_URL, "http://www.eslteachersboard.com/cgi-bin/esljobs/index.pl?post");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "name=$name&email=$email&subject=$location&body=$desc&url=$url");
curl_exec ($ch);
curl_close ($ch);
echo"<br> Completed CURL <br><br>";

...

?>

This code works on 'test' websites i have set up with the ENCTYPE=application/x-www-form-urlencoded with no problems.

When i try to post the EXACT same to the ESL Job Board mentioned at the top of this discussion, and i allow the CURL code to follow the result, I see that NONE OF THE VARIALBES are being passed and the POST obviously fails (due to the error message i get - "you didn't fill in the name, email, etc...")

I know this question has been asked a billion times on phpbuilder, but i haven't seen the formal answer i am looking for.

Additional information:
1. I am not attempting to upload a file, only variables
2. The form type=multipart/form-data and this is unchangable by me
3. I am running off of the following (steadfast networks) virtual servers
Apache: 1.3.34
Perl: 5.8.0
PHP: 4.4.1
MySQL: 4.0.26
PostgreSQL: 7.4.11

I would appricated any help in solving this problem, as this is the last step to get my website/php working!! THANKS IN ADVANCE,

    [man]register_globals[/man] is switched off (as it should be) use the $GET and $POST super globals.

      bubblenut wrote:

      use the $GET and $POST super globals.

      I am currently reading as much about $POST as i can, there are alot of posts on phpbuilder.com which discuss $POST and $_GET.

      Is there anything obviously wrong with my code?

      Is there anything wrong with this line?

      curl_setopt($ch, CURLOPT_POSTFIELDS, "name=$name&email=$email&subject=$location&body=$desc&url=$url");
      

      Thanks for the assistance bubblenut

        Not trying to bump my post, but i am unable to find the answer to my question, or lack the knowledge required to understand the answer.

        How do i post to a multipart form which is off-site (aka. i must CURL to it)? What, if any, are the requirements?

        Currently, when i post, i lose my data, using the code which i posted at the top of this discussion. I can, as stated above, post to my own test forms of non multi-part form ENCTYPE.

        This is very frustrating, because the POST operation is so basic! I'm guessing that i have missed something basic about PHP and/or CURL...

        Thanks for any help and God bless programming.

          Once again, not trying to bump my post, but do i simply need to compress all my variables into one array in order to post to a multi-part form

          To clairfy:

          
          ...
          
          $id=mysql_result($result,$i,"jobid");
          $name=mysql_result($result,$i,"company");
          $email=mysql_result($result,$i,"email");
          $location=mysql_result($result, $i, location");
          $desc=mysql_result($result,$i,"description");
          $url=mysql_result($result,$i, "url");
          
          echo "<br>$id<br>$name<br>$email<br>$location<br>$desc<br>$url<br>";
          
          /* Post data to website */
          
          $ch = curl_init();
          curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
          curl_setopt($ch, CURLOPT_URL, "http://www.eslteachersboard.com/cgi-bin/esljobs/index.pl?post");
          curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
          curl_setopt($ch, CURLOPT_POST, 1);
          curl_setopt($ch, CURLOPT_POSTFIELDS, "name=$name&email=$email&subject=$location&body=$desc&url=$url");
          curl_exec ($ch);
          curl_close ($ch);
          echo"<br> Completed CURL <br><br>";
          
          ...
          
          

          Should this actually be:

          
          ...
          
          $postfields = array();
          $postfields[] = array("firstname", $_POST['jobid']);
          $postfields[] = array("lastname", $_POST['company']);
          $postfields[] = array("ccnumber", $_POST['email']);
          $postfields[] = array("expmonth", $_POST['location']);
          $postfields[] = array("expyear", $_POST['description']); 
          $postfields[] = array("expyear", $_POST['url']); 
          
          ...
          
          curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields); 
          
          ...
          
          

          Is the problem i am experiening the fact that i am trying to post multiple variables to a multipart form?? Would the above $postfields array variable solve my problem??

          THANKS AGAIN PHPBUILDER.COM peoples, you rock my socks.

            Are you using the $POST fields? CURLOPT_POSTFIELDS expects a string but the data from the form has to be accessed through the $POST array. Before you post again try putting something together and testing it out. If it doesn't work then post up the new code (in full). Try not to get into the habit of posting over avd over rather than trying out different methods.

              bubblenut wrote:

              Try not to get into the habit of posting over avd over rather than trying out different methods.

              Yeah I got a little excited, i'll see what i can figure out and try, try again.

              Thanks again Bubblenut!

                Hmmm, still not sure what is going one because i have created a multipart/form-data
                form and posted to it no problem.

                So here is my complete code:

                <html>
                
                <body>
                
                <?php
                  /* VARIABLES */
                  $false=0; //FALSE
                  $true=1;  //TRUE
                
                  $temp=-1;  //temp
                
                
                  /* CONNECT TO DATABASE */
                  $host="xxxx";
                  $uname="xxxx";
                  $pass="xxxx";
                  $database="xxxx";
                  $tablename="xxxx";
                  $connection= mysql_connect($host,$uname,$pass);
                
                  if(!$connection)
                  {
                    die("Database connection failed ! <br>");
                  }
                  else
                  {
                    echo "logged into MySQL Server ", $host, " successfully.<br>";
                  }
                
                  $result=mysql_select_db($database);
                  if (!$result)
                  {
                    die("Database could not be selected");
                  }
                  else
                  {
                    echo "Database ", $database, " ready to be used.<br><br>";
                  }
                
                
                  /* USER clicked remove button */
                  if($_POST['submit'])
                  {
                    /* User did NOT eneter a job id */
                    if(!$jobid)
                    {
                      printf("you must enter a valid job id number from the database cletus!");
                    }
                
                /*user entered a job id number */
                else
                { 
                   $query="SELECT jobid FROM mark";
                   $result=mysql_query($query);  
                
                   while ($row = mysql_fetch_object($result))
                   {
                      if($row->jobid == $jobid)
                      {
                        $temp=$true; 
                       }
                   }//while
                
                   /* MAIN LOOP */
                   if($temp == $true){
                     printf("Job ID valid.");
                
                     /* MARKS ESL JOB BOARD */
                     if($marks)
                     {
                       printf("You checked MARKS ESL\n");
                
                       /* Retrieve data from DB */
                       $query="SELECT * FROM mark WHERE jobid = $jobid";
                       $result=mysql_query($query);  
                
                       printf("Job Preview:");
                       echo "<br>--------------------------------<br>";
                       $id=mysql_result($result,$i,"jobid");
                       $name=mysql_result($result,$i,"company");
                       $email=mysql_result($result,$i,"email");
                       $location=mysql_result($result, $i, "location");
                       $desc=mysql_result($result,$i,"description");
                       $url=mysql_result($result,$i, "url");
                
                       echo "<br>$id<br>$name<br>$email<br>$location<br>$desc<br>$url<br>";
                
                       /* Post data to website */
                
                       $ch = curl_init();
                       curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
                       curl_setopt($ch, CURLOPT_URL, "http://www.eslteachersboard.com/cgi-bin/esljobs/index.pl?post");
                       curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0);
                       curl_setopt($ch, CURLOPT_POST, 1);
                       curl_setopt($ch, CURLOPT_POSTFIELDS, "name=$name&email=$email&subject=$location&body=$desc&url=$url");
                       curl_exec ($ch);
                       curl_close ($ch);
                
                       echo"<br> Completed CURL <br><br>";
                
                       //print_r($HTTP_POST_VARS);
                
                
                       /* Print report/email report */
                
                     }
                
                     if(!$marks)
                     {
                       printf("You didn't check any websites to submit to cletus!");
                     }  
                   }//if ($temp == true)
                
                }//else
                
                  }//submit
                
                
                  /*User clicked preview before removal */
                  else if ($_POST['preview']){
                
                /* User did NOT eneter a job id */
                if(!$jobid)
                {
                  printf("you must enter a valid job id number from the database cletus!");
                }
                
                /*user entered a job id number */
                else
                { 
                   $query="SELECT * FROM mark WHERE jobid = $jobid";
                   $result=mysql_query($query);  
                
                   while ($row = mysql_fetch_row($result))
                   {
                      if($row[0] = $jobid)
                      {
                        $temp=$true; 
                       }
                   }//while
                
                   if($temp == $true){
                     printf("Job Preview:");
                     echo "<br>--------------------------------<br>";
                     $id=mysql_result($result,$i,"jobid");
                     $name=mysql_result($result,$i,"company");
                     $email=mysql_result($result,$i,"email");
                     $location=mysql_result($result, $i, "location");
                     $desc=mysql_result($result,$i,"description");
                     $url=mysql_result($result,$i, "url");
                
                     echo "<br>$id<br>$name<br>$email<br>$location<br>$desc<br>$url<br>";
                   }
                }//else
                
                  }
                
                
                  /*user arrived at this page without clicking on the remove button...*/
                  else
                  {
                    print_r($_POST);
                    printf("No option selected");
                  }
                
                  mysql_close();
                ?>
                
                <center> <A href="bluetech.htm"> Click here</a> to return to Bluetech Mainpage.</center>
                </body>
                </html>
                
                
                

                Please note:
                I am posting to the form's ACTION and am not posting directly to the website/html

                In this case the website i mention is:
                http://www.eslteachersboard.com/cgi-bin/esljobs/index.pl?form=0

                And the website form action is:
                http://www.eslteachersboard.com/cgi-bin/esljobs/index.pl?post

                Please let me know if there is anything else i can provide to solve this problem.

                Thanks once again, gals and guys!

                      /* User did NOT eneter a job id */
                      if(!$jobid)
                      {
                        printf("you must enter a valid job id number from the database cletus!");
                      } 
                  

                  Where are you getting $jobid? It's comming from the form right? It's being posted by the form right? So, if [man]register_globals[/man] is switched off it won't have been expanded into the local space right? So you'll have to access it via the $_POST variable. I've not checked any further to see if there are any other errors.

                    bubblenut wrote:

                    Where are you getting $jobid? It's comming from the form right? It's being posted by the form right?

                    jobid is used in mysql DB and is NOT a part of the form. All the data is retrieved FROM a DB and a post request is made with this data except $jobid.

                    So, if [man]register_globals[/man] is switched off it won't have been expanded into the local space right? So you'll have to access it via the $_POST variable. I've not checked any further to see if there are any other errors.

                    Check away my good man/woman, thanks for all your help! I feel like i'm so close but i really am at a deadstop, my code hasn't changed to any positive affect in about 5 days...

                      Well, either that's not the entire script or $jobid is coming from somewhere else because it's not being set there. Also, there is only one place that $_POST is being accessed and that's just to check if the form has been submitted.
                      With regard to the restof the code there are some rather fundemental errors. I'm not going to give you outright answers because I don't believe in that where I can see an oportunity to guide.
                      Firstly, where does the $true variable come from? Do you mean just true? Secondly the logic of that whole code, let's see what's happening.

                      get all jobs from the mark table
                      iterate through all jobs
                      if the jobid is equal to the jobid from the user
                      mark a temporary variable as true

                      This is horribly inefficient, you could simply use the where clause and then when you do a mysql_fetch_object check the result to see if you've got anything. Your way you're getting everything out of the table and then hitting the table again further down to get teh job data out. Also, when you're calling mysql_result $i has never been set. It's only by chance that php evaludates an uninitialized variable as null which in turn converts to a zero when parsed to an integer.

                      I think you need to check the php manual for every function that you're using to make sure you're really sure you understand how each of them works.

                        bubblenut wrote:

                        Well, either that's not the entire script or $jobid is coming from somewhere else because it's not being set there.

                        $jobid is coming from somewhere else: my form which allows the user to specify the job id and websites. $jobid is simply an int the user specifies in the above mentioned form - it is never sent to the server side of this attempt at a post request.

                        Also, there is only one place that $_POST is being accessed and that's just to check if the form has been submitted.

                        You are correct, but I think there is a major miscommunication going on... My intention is to send the data TO an external website via this code. This is NOT the server side code which recieves a post submission (okay it is, but that stuff is my side). The actual server side code which recieves the CURL request is completely unknown to me.

                        my form(specify $jobid and websites) -> my php(curl request) -> external website (which gives me errors)

                        With regard to the restof the code there are some rather fundemental errors...
                        Firstly, where does the $true variable come from? Do you mean just true?

                        Yes, i just mean true. $true is declared at the top of the php code.

                        Secondly the logic of that whole code, let's see what's happening.

                        get all jobs from the mark table
                        iterate through all jobs
                        if the jobid is equal to the jobid from the user
                        mark a temporary variable as true

                        This is horribly inefficient, you could simply use ...

                        I agree, i'm new to php and must improve my code - its a hack job.

                        Also, when you're calling mysql_result $i has never been set. It's only by chance that php evaludates an uninitialized variable as null which in turn converts to a zero when parsed to an integer.

                        Correct, this was my intention - i only get a warning for doing this.

                        I think you need to check the php manual for every function that you're using to make sure you're really sure you understand how each of them works.

                        Agreed! :-)

                          MasterCJ wrote:

                          You are correct, but I think there is a major miscommunication going on... My intention is to send the data TO an external website via this code. This is NOT the server side code which recieves a post submission (okay it is, but that stuff is my side). The actual server side code which recieves the CURL request is completely unknown to me.

                          I'm not talking about the curl stuff. There is a form which is submitting to your script, it is this which must be recieved with $POST. $POST['jobid'] instead of just $jobid.

                            bubblenut wrote:

                            I'm not talking about the curl stuff. There is a form which is submitting to your script, it is this which must be recieved with $POST. $POST['jobid'] instead of just $jobid.

                            Bubblenut,

                            Firstly, thank you for your continued help with my project, I really appricate you taking the time.

                            Second, I don't think that the $_POST['jobid'] is the issue. If the jobid value was not being passed, i would never be able to retrieve the correct data from my SQL DB and then echo it to screen.

                            I am referring to this code:

                            <?
                            
                            ...
                            
                               $query="SELECT jobid FROM mark";
                               $result=mysql_query($query);  
                            
                               while ($row = mysql_fetch_object($result))
                               {
                                  if($row->jobid == $jobid)
                                  {
                                    $temp=$true; 
                                   }
                               }//while
                            
                               /* MAIN LOOP */
                               if($temp == $true){
                                 printf("Job ID valid.");
                            
                                 /* MARKS ESL JOB BOARD */
                                 if($marks)
                                 {
                                   printf("You checked MARKS ESL\n");
                            
                                   /* Retrieve data from DB */
                                   $query="SELECT * FROM mark WHERE jobid = $jobid";
                                   $result=mysql_query($query);  
                            
                                   printf("Job Preview:");
                                   echo "<br>--------------------------------<br>";
                                   $id=mysql_result($result,$i,"jobid");
                                   $name=mysql_result($result,$i,"company");
                                   $email=mysql_result($result,$i,"email");
                                   $location=mysql_result($result, $i, "location");
                                   $desc=mysql_result($result,$i,"description");
                                   $url=mysql_result($result,$i, "url");
                                   $post="Post Message";
                                   //$reffer = "";
                                       echo "<br>$id<br>$name<br>$email<br>$location<br>$desc<br>$url<br>";
                            ...
                            
                            
                            

                            That echo statement always prints the correct information. I don't believe that $jobid needs to be altered to $_POST['jobid'] because the information printed is accurate.

                            Am I missing something? Is testing via print/echo statements not the correct method to check my data? Why does programming have to be so much fun? :-P

                              5 years later

                              Dear asker i have the same problem as u do
                              i found out multi frame post has structures like this

                              post data:

                              -----------------------------12249266671528
                              Content-Disposition: form-data; name="title"

                              Filme 2010, filme 2009, filme noi, programe TV, program cinema, premiere cinema, trailere filme - CineMagia.ro
                              -----------------------------12249266671528
                              Content-Disposition: form-data; name="category"

                              3
                              -----------------------------12249266671528
                              Content-Disposition: form-data; name="tags"

                              filme, programe tv, program cinema
                              -----------------------------12249266671528
                              Content-Disposition: form-data; name="bodytext"

                              Filme 2010, filme 2009, filme noi, programe TV, program cinema, premiere cinema, trailere filme
                              -----------------------------12249266671528
                              Content-Disposition: form-data; name="trackback"

                              -----------------------------12249266671528
                              Content-Disposition: form-data; name="url"

                              http://cinemagia.ro
                              -----------------------------12249266671528
                              Content-Disposition: form-data; name="phase"

                              2
                              -----------------------------12249266671528
                              Content-Disposition: form-data; name="randkey"

                              9510520
                              -----------------------------12249266671528
                              Content-Disposition: form-data; name="id"

                              17753
                              -----------------------------12249266671528--

                              but i dont know how to generate that seperator number.
                              and i did not tried the exact number.
                              U try
                              i mean use this structure and put UR data in it
                              and send by CURL.
                              morteza kavakebi
                              BEST Regard.😉

                                10 months later

                                How about this :
                                http://dtbaker.com.au/random-bits/uploading-a-file-using-curl-in-php.html

                                example uploading a file using Curl in PHP:

                                <?php
                                    $ch = curl_init();
                                    curl_setopt($ch, CURLOPT_HEADER, 0);
                                    curl_setopt($ch, CURLOPT_VERBOSE, 0);
                                    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
                                    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
                                    curl_setopt($ch, CURLOPT_URL, _VIRUS_SCAN_URL);
                                    curl_setopt($ch, CURLOPT_POST, true);
                                    // same as <input type="file" name="file_box">
                                    $post = array(
                                        "file_box"=>"@/path/to/myfile.jpg",
                                    );
                                    curl_setopt($ch, CURLOPT_POSTFIELDS, $post); 
                                    $response = curl_exec($ch);
                                ?>
                                

                                  notice the @ infront of the file path, this is the magic part.

                                    Write a Reply...