Javascript, or Jquery and posting to php

I want to send a javascript variable to a php file. What I would like to know is could you do it via this method?

Jquery:

Var UserName;
UserName = John;
$.post("InsertRunInfo.php", { UserName: UserName } );

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

Leave a Reply

*

Hire Me
Follow Me!
Search
Most Popular Articles & Pages
Because your vote is Important
Sorry, there are no polls available at the moment.
Categories