我想将 javascript 变量发送到 php 文件。我想知道的是你能通过这种方法做到吗?
查询:
Var UserName;
UserName = John;
$.post("InsertRunInfo.php", { UserName: UserName } );
传递给 php:
<?php
$con = mysql_connect("*****","*****","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("runtracker", $con);
$sql="INSERT INTO userinfo (UserName)
VALUES
('$_POST[UserName]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con);
?>