0

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);
5
  • 1
    Please elaborate on what you mean by "didn't work". And what is macs? It is not a standard object and not defined anywhere in your code. Commented Jan 25, 2010 at 5:26
  • Add some echo's to see what's going on and call your script directly from the browser. Your problem could be anywhere from the mac var being empty to your mysql connection not being made to the database. Commented Jan 25, 2010 at 5:27
  • hmm.. okay i edit my post again.. Pls help.. Commented Jan 25, 2010 at 5:36
  • Ah I see you went with my brief code. It will probably require some error checking etc Commented Jan 25, 2010 at 5:37
  • error checking as in?? which part? i thought it would be a simple coding.. Commented Jan 25, 2010 at 5:50

1 Answer 1

4

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'); })
});
Sign up to request clarification or add additional context in comments.

9 Comments

Wow, I totally missed that =x
throw a quick and dirty echo mysql_error() after mysql_query(). Also, have you connected to your database?
Going to go with my original comment, try calling it directly from the browser: 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.
hmm.. i tried to call it manually from the browser, and it works... but how come it doesnt call up properly...
is my form having this issue here?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.