douyinjiao9351 2014-11-06 15:45
浏览 39

如何在php文件中接收我的变量(来自javascript代码)

I have two .php files cotiza.phpandinsertCot.php

In cotiza.php I have some inputs and a button, the button has a onClick function, I take the values of my inputs and send them to the javascript function:

<button type="button" onClick="GuardacotizacionaBD(document.getElementById('pais').value, document.getElementById('proyecto').value, 
    document.getElementById('notas').value, document.getElementById('formapago').value, document.getElementById('fechaentrega').value, 
    document.getElementById('flete').value, 
    document.getElementById('instalacion').value,
    document.getElementById('venta').value, 
    document.getElementById('total').value);">Realizar</button> //It works, I have not problem with this

in my function I get the values and I send them to insertaCot.php

function  GuardacotizacionaBD (pais, proyecto, notas, formapago, fechaentrega, flete, instalacion, venta, total)
{
 xmlhttp=new XMLHttpRequest();
xmlhttp.open("POST","insertaCot.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send("pais="+pais+"&proyecto="+proyecto);

location.reload(true)
}

In insertaCot.php I receive them: To try to do an INSERT to a table on MySql

<?
include('conexion.php');
$coninsert=conexion();

$pais= $_POST['pais'];//this is line 22
$proyecto= $_POST['proyecto'];//this is line 23
//all my vars
?>

BUT i get this:

Undefined index: pais in C:\xampp\htdocs\insertaCot.php on line 22
Undefined index: proyecto in C:\xampp\htdocs\insertaCot.php on line 23

I print my form on insertCot, but it doesn't have values:

Array
(
)

Any idea about what could i do?

I have the same dimamic in 2 .php files and the work.

thank you

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 2024-五一综合模拟赛
    • ¥15 下图接收小电路,谁知道原理
    • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
    • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
    • ¥15 手机接入宽带网线,如何释放宽带全部速度
    • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
    • ¥15 ETLCloud 处理json多层级问题
    • ¥15 matlab中使用gurobi时报错
    • ¥15 这个主板怎么能扩出一两个sata口
    • ¥15 不是,这到底错哪儿了😭