Page 1 of 1

php grabbing data from javascript

Posted: Sun Jan 24, 2010 10:55 pm
by kennedysee
Apparently i try to save the data into the mysql, but it didnt work.. Anyone help?

create_users.php

<script type="text/javascript">
var mac = macs.getMacAddress();
$.get('/create_users.php?mac=' + mac, function() { alert('yeah done'); })
</script>


checkAvailability.php

$mac = $_GET['mac'];
$mac = mysql_real_escape_string($mac);
$sql = "INSERT INTO test(mac) VALUES ('$mac')";
mysql_query($sql);

Re: php grabbing data from javascript

Posted: Mon Jan 25, 2010 12:17 am
by josh
The file name is different/wrong...

Re: php grabbing data from javascript

Posted: Mon Jan 25, 2010 12:42 am
by kennedysee
Manage to get it change.... it only works when i manually called up from the browser...
http://localhost/checkAvailability.php?mac=555

create_users.php

Code: Select all

       <form method="post" action="checkAvailability.php">
            <script type="text/javascript">
                    var macs = {
                        getMacAddress : function()
                        {
                            document.macaddressapplet.setSep( "-" );
                            return (document.macaddressapplet.getMacAddress());
                        }
                    }
                </script>
        
    
        <script type="text/javascript">
        var mac = macs.getMacAddress(); 
        $.get('/createAvailability.php?mac=' + mac, function() { alert('yeah done'); }) 
        </script>
    </form>
checkAvailability.php

Code: Select all

 $dbhost = 'localhost';
    $dbuser = 'root';
    $dbname = 'registration';
    mysql_connect($dbhost, $dbuser);
    mysql_select_db($dbname);
    $mac = $_GET['mac'];
    $mac = mysql_real_escape_string($mac);
    $sql = "INSERT INTO test(mac) VALUES ('$mac')";
    mysql_query($sql);
    echo mysql_error();