通过get url发送数据

时间:2017-09-08 18:29:44

标签: php

我有一个问题,我无法解决,我变得疯狂。我有这个链接使用get方法将数据传递到远程数据库。

这是链接

$res = get_data('http://www.campionandoalivorno.it/iwebkit/set_register.asp?' . 'user=' . urlencode($user) . '&pwd=' . urlencode($pwd) . '&email=' . urlencode($email) . '&recapito=' . urlencode($recapito)  . '&fanta=' . urlencode($fanta) . '&cognome=' . urlencode($cognome) . '&squadra=' . urlencode($squadra));

这是最小化的代码,以便您删除所有错误:

    $user = $_POST['user'];
$psw = $_POST['psw'];
$email = $_POST['email'];
$recapito = $_POST['recapito'];
$email = $_POST['cognomenome'];
$sq = $_POST['squadra'];
$fanta = "ecce";

echo $user, $psw, $email, $recapito, $email, $sq, $fanta;

$res = get_data('http://www.campionandoalivorno.it/iwebkit/set_register.asp?' . 'user=' . urlencode($user) . '&pwd=' . urlencode($pwd) . '&email=' . urlencode($email) . '&recapito=' . urlencode($recapito)  . '&fanta=' . urlencode($fanta) . '&cognome=' . urlencode($cognome) . '&squadra=' . urlencode($squadra));

如果我直接从浏览器传递链接,文本字符串工作grrrrr,我无法理解。 非常感谢谁能帮助我

1 个答案:

答案 0 :(得分:0)

$cognome$squadra不存在,但您尝试将其添加到网址中。请注意,您有$sq但未在网址中使用它,并且您已尝试将$email设置两次。 psw怎么样?你的意思是pwd?所以你可能意味着这样做:

$user     = $_POST['user'];
$pwd      = $_POST['psw'];
$email    = $_POST['email'];
$recapito = $_POST['recapito'];
$cognome  = $_POST['cognomenome'];
$sq       = $_POST['squadra'];
$fanta    = "ecce";


$res = get_data('http://www.campionandoalivorno.it/iwebkit/set_register.asp?' . 'user=' . urlencode($user) . '&pwd=' . urlencode($pwd) . '&email=' . urlencode($email) . '&recapito=' . urlencode($recapito)  . '&fanta=' . urlencode($fanta) . '&cognome=' . urlencode($cognome) . '&squadra=' . urlencode($sq));

为了获得更好的体验,也许可以试试这个:

<?php

$query_string = http_build_query(array(
    'fanta'    => "ecce",
    'user'     => (isset($_POST['user'])        ? $_POST['user']        : ''),
    'pwd'      => (isset($_POST['psw'])         ? $_POST['psw']         : ''),
    'email'    => (isset($_POST['email'])       ? $_POST['email']       : ''),
    'recapito' => (isset($_POST['recapito'])    ? $_POST['recapito']    : ''),
    'cognome'  => (isset($_POST['cognomenome']) ? $_POST['cognomenome'] : ''),
    'squandra' => (isset($_POST['squadra'])     ? $_POST['squandra']    : '')
));

$res = get_data('http://www.campionandoalivorno.it/iwebkit/set_register.asp?' . $query_string);