连接一个php $post_data[与html代码

tyu7yeag  于 2023-05-16  发布在  PHP
关注(0)|答案(3)|浏览(78)

我有以下代码:

<?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);
?>

如何将其连接到HTML表单,以便某人可以在HTML页面中输入其详细信息,并且其值将被重定向到此PHP代码?
我的HTML代码是:

<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">
axr492tv

axr492tv1#

你应该这样写:第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>

页面2 - PHP - page2.php

<?PHP
echo $_POST['firstname'];
echo $_POST['lastname'];
echo $_POST['address'];
?>
tgabmvqs

tgabmvqs2#

使用$_POST超全局。例如,如果输入nameName,那么你会这样做:

<?php
echo 'Your name is ' . $_POST['Name'];
?>
vktxenjb

vktxenjb3#

my_php.PHP

$post_data = $_POST;

相关问题