-1

I have the following code:

<?php
$post_data['firstname'] = '';
$post_data['lastname'] = '';
$post_data['address'] = '';


foreach ( $post_data as $key => $value)
{
$post_items[] = $key . '=' . $value;
}

$post_string = implode ('&', $post_items);
$curl_connection = curl_init('https://example.com/app.php');
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);
curl_setopt($curl_connection, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
$result = curl_exec($curl_connection);
echo "Result: " . $result . "<br><br>";
print_r(curl_getinfo($curl_connection));
echo curl_errno($curl_connection) . '-' . curl_error($curl_connection);
curl_close($curl_connection);
?>

How do I connect it to an HTML form so that someone can enter their details in an HTML page and its value will be redirected to this PHP code?

my HTML code is:

<form name="form" method="post" action="my_php.php">
<input name="firstname" type="text" ID="firstname" value="first name">
<input name="lastname" type="text" ID="lastname" value="last name">
<input name="address" type="text" ID="address" value="address">
<input type="submit" name="Submit" value="Submit">
aynber
  • 22,380
  • 8
  • 50
  • 63

3 Answers3

2

You should write something like this: PAGE 1 - HTML - page1.html

<FORM ACTION='page2.php' METHOD='POST'>
<input name="firstname" type="text" ID="lastname" value="first name">
<input name="lastname" type="text" ID="lastname" value="last name">
<input name="address" type="text" ID="address" value="address">
<input type="submit" name="Submit" value="Submit">
</FORM>

PAGE 2 - PHP - page2.php

<?PHP
echo $_POST['firstname'];
echo $_POST['lastname'];
echo $_POST['address'];
?>
Alin Alexandru
  • 139
  • 1
  • 6
  • I'm almost sure that you don't need in the first page, the following code: _ID="lastname" value="first name"_, and same for the others. Php Post works only with _name="firstname"_ – Alin Alexandru Mar 23 '13 at 19:10
  • when there is "foreach ( $post_data as $key => $value)" we can not use "$_POST['']" and one field i have to use in that is "$post_data['ip_address'] = $_SERVER["REMOTE_ADDR"];" is there any other solution ? – Shashank Malik Mar 23 '13 at 19:13
1

Use the $_POST superglobal. Example, if the input name is Name, then you would do:

<?php
echo 'Your name is ' . $_POST['Name'];
?>
mishmash
  • 4,422
  • 3
  • 34
  • 56
0

my_php.PHP

$post_data = $_POST;
Amir
  • 4,089
  • 4
  • 16
  • 28
  • Thanks for this one, i have inserted this code in my php code and it is under review with my service provider and it will be cleared out within 2 days. Hopefully it will work – Shashank Malik Mar 24 '13 at 14:54