php grabbing data from javascript
Apparently i try to save the data into the mysql, but it didnt work.. Anyone help?
create_users.php
<form method="post" action="checkAvailability.php">
<script>
var macs = {
g开发者_Python百科etMacAddress : function()
{
document.macaddressapplet.setSep( "-" );
return (document.macaddressapplet.getMacAddress());
}}jQuery(document).ready(function(){
var mac = macs.getMacAddress();
$.get('/checkAvailability.php?mac=' + mac, function() { alert('yeah done'); })
});
</script>
<script type="text/javascript">
document.write(macs.getMacAddress());
</script>
</form>
checkAvailability.php
$dbhost = 'localhost';
$dbuser = 'root';
$dbname = 'registration';
mysql_connect($dbhost, $dbuser) or die("Could not connect database");
mysql_select_db($dbname);
$mac = $_GET['mac'];
$mac = mysql_real_escape_string($mac);
$sql = "INSERT INTO test(mac) VALUES ('$mac')";
mysql_query($sql);
You are calling "create_users.php" in your $.get() method instead you should be calling "checkAvailability.php"..
And try this for your client side form:
var macs = {
getMacAddress : function()
{
document.macaddressapplet.setSep( "-" );
return (document.macaddressapplet.getMacAddress());
}}jQuery(document).ready(function(){
var mac = macs.getMacAddress();
$.get('/checkAvailability.php?mac=' + mac, function() { alert('yeah done'); })
});
精彩评论