Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8686315
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:48:48+00:00 2026-06-12T22:48:48+00:00

I am trying to submit form from one site to another website by using

  • 0

I am trying to submit form from one site to another website by using cURL. However it is giving me some $fields_string variable error (Undefined variable).

This is the very first time I am working with cURL and don’t have much knowledge regarding it. So please guide me to solve this issue where I can submit form successfully.

Information: I am now working on localhost and trying to submit form on localhost another website for testing.

Here is my code

<?php

    $url = 'http://localhost/qa/ask';
    $fields = array(

                'title'=>urlencode($_POST['title']),
                'content'=>urlencode($_POST['content']),
                'tags'=>urlencode($_POST['tags']),
                'q_notify'=>urlencode($_POST['q_notify']),

            );


    foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
    rtrim($fields_string,'&');    

    $ch = curl_init();

    curl_setopt($ch,CURLOPT_URL,$url);
    curl_setopt($ch,CURLOPT_POST,count($fields));
    curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);

    $result = curl_exec($ch);

    curl_close($ch);
?>

This is my html form

<form action="submit.php" method="POST"> 
    <INPUT NAME="title" TYPE="text" CLASS="qa-form-tall-text custom-ask-text" value="" placeholder="Ask your question" autocomplete="off" role="textbox"> 

    <TEXTAREA NAME="content" CLASS="qa-form-tall-text"></TEXTAREA>

    <INPUT NAME="tags" TYPE="text" CLASS="qa-form-tall-text custom-ask-text" value=""> 

    <label><input type="checkbox" class="qa-form-tall-checkbox" checked="" value="1" name="q_notify">Email me if my question is answered or commented on</label>

    <INPUT CLASS="custom-ask-submit" TYPE="submit" value="ask"> 

    <INPUT TYPE="hidden" NAME="doask1" VALUE="1"> 
</form>

Thanks you

EDIT: NEW CODE

<?php

$url = 'http://localhost/qa/ask';
$fields = array(
            'title'=>$_POST['title'],
            'content'=>$_POST['content'],
            'tags'=>$_POST['tags'],
            'q_notify'=>$_POST['q_notify'],

        );

$fields_string = '';
foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }

$ch = curl_init();

curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields);

$result = curl_exec($ch);

curl_close($ch);

?>

If everything is right than may be I am assigning wrong url. I am using question2answer.org script and want to make form where my user can submit form/question from my other website.

EDIT:
@GBD

Curl error: array(22) { ["url"]=> string(23) "http://localhost/qa/ask" ["content_type"]=> string(24) "text/html; charset=utf-8" ["http_code"]=> int(200) ["header_size"]=> int(443) ["request_size"]=> int(211) ["filetime"]=> int(-1) ["ssl_verify_result"]=> int(0) ["redirect_count"]=> int(0) ["total_time"]=> float(0.141) ["namelookup_time"]=> float(0) ["connect_time"]=> float(0.016) ["pretransfer_time"]=> float(0.016) ["size_upload"]=> float(87) ["size_download"]=> float(16130) ["speed_download"]=> float(114397) ["speed_upload"]=> float(617) ["download_content_length"]=> float(-1) ["upload_content_length"]=> float(87) ["starttransfer_time"]=> float(0.141) ["redirect_time"]=> float(0) ["certinfo"]=> array(0) { } ["redirect_url"]=> string(0) "" } 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T22:48:49+00:00Added an answer on June 12, 2026 at 10:48 pm

    You’re appending to $fields_string;

    foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
    

    without setting $fields_string to a start value first. Just set it to the empty string first and the error will disappear;

    $fields_string = '';
    foreach($fields as $key=>$value) { $fields_string .= $key.'='.$value.'&'; }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using this code. Trying to pass form values from one internal page
I'm trying to submit a form when a select changes using jQuery Mobile. I
I have this code. Trying to pass form values from one internal page to
I am trying to submit a form from Ext JS 4 to a Spring
I am trying to submit a form using jsRoutes in ajax after first doing
I have been trying to access data from another site by ajax but failed.
I am trying to intercept form submits from webpages I dont control. My current
I'm trying to submit a form (it's a dynamic form with fields added via
I'm trying to submit a form entry with an uploaded file, but I can't
I am trying to submit a form with method GET and action index.php?id=3. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.