1

我无法让它工作 - 这是我第一次尝试。我确实意识到信息还没有被序列化,我只是想让它先工作。

有什么想法我在这里做错了吗?它不会将信息保存到 mysql 数据库中。

索引.html:

<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript" src="purchase.js"></script>
</head>

<form name="paypal_form" onsubmit="return validate_form();" method="post">
<input type="text" size="25" name="os0" value="">
<input type="text" size="25" name="os1" value="">
<input type="hidden" name="item_name" value="product">
<input type="image" src="images/paypal.gif" name="submit">
</form>

付款.js:

function validate_form()
{

// code to validate form data 
//  ....


    valid = true;

    var regcode = document.paypal_form.os0.value;
    var email = document.paypal_form.os1.value;
    var product = document.paypal_form.item_name.value;

    var dataString = 'regcode=' + regcode + '&email=' + email + '&product=' + product;

    $.ajax({
        url: "/process.php",
        type: "POST",
        data: dataString,
        success: function()
        {
            alert("Order Submitted");
        }
    });

    return valid;
}

进程.php:

$dbhost = "localhost";
$dbuser = "dbuser";
$dbpass = "dbpass";
$dbname = "dbname";

$date = date('Y/m/d');

$RegCode = $_POST['regcode'];
$Email = $_POST['email'];
$Product = $_POST['product'];

mysql_connect($dbhost, $dbuser, $dbpass);

// Store the transaction ID in the database
mysql_query("INSERT into payment (date, regcode, sentemail, status) values ('$date', '$RegCode', '$Email', '$Product')");
4

2 回答 2

0

如果 process.php 在同一个文件夹中,请将其设为 url:'process.php' 并且

mysql_connect($dbhost, $dbuser, $dbpass);
mysql_select_db("dbname", $con);
于 2012-06-04T05:50:48.467 回答
0

在表单标签中添加以下属性并尝试

action="javascript:void(0);"
于 2012-06-04T06:03:04.430 回答