tags:

views:

69

answers:

1

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 = { 
    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'); }) 
    }); 
</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);
+4  A: 

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'); })
});
thinktejas
Wow, I totally missed that =x
Erik
tried.. it doesnt work.. it didnt save to the database.
kennedy
throw a quick and dirty echo `mysql_error()` after `mysql_query()`. Also, have you connected to your database?
alex
same.. doesnt work. yeap, connected to database..
kennedy
Going to go with my original comment, try calling it directly from the browser: http://yoursite.com/checkAvailability.php?mac=555 Add some echo statements to check your SQL and a `or die(mysql_error());` after the query. If the direct call puts a record in your database, then at least you know the problem is on the front-end.
Erik
hmm.. i tried to call it manually from the browser, and it works... but how come it doesnt call up properly...
kennedy
is my form having this issue here?
kennedy
I have edited my answer.. I suppose you are using a java applet to populate the macs variable, it would be logical to call the related function on document load.
thinktejas
hmm...tried, still not working... will my checkAvailability url display the MAC Address?and a simple document.write(macs.getMacAddress()) also not working anymore..
kennedy
The location of jQuery(document).ready( is not allowing the document.write(macs.getMacAddress()) to work. Please use the updated script.
thinktejas
thanks for the prompt answer... but still didnt work, i did a check on mysql.. the mac column is empty..
kennedy