php grabbing data from javascript

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kennedysee
Forum Newbie
Posts: 14
Joined: Fri Dec 04, 2009 12:17 am

php grabbing data from javascript

Post 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);
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: php grabbing data from javascript

Post by josh »

The file name is different/wrong...
kennedysee
Forum Newbie
Posts: 14
Joined: Fri Dec 04, 2009 12:17 am

Re: php grabbing data from javascript

Post 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();
Post Reply