Can't get it to insert into the database

PHP using AJAX INSERT INTO MYSQL

Posted 19 October 2010 - 06:58 PM

Hello there guys! I'm new with AJAX and I can't seem to find the solution to my problem in the internet. Some might find this too easy to do but I don't have any idea about how to use AJAX and I'm trying to self-study it, so here is my question, what is the syntax I need to insert the two values from my html page to my mysql database?

The 'add_info' function might be called on a submit or change event, and it calls changesomething after placing values in the global variables 'func' and 'param' which are used by eval to open the appropriate function 'func' to handle the response, along with any parameter 'param' I wish to pass to that function. The php file uses $_GET to receive the variable(s) being sent to it.

It may look complicated, but if you spend a little time with it you'll see that it works well and can be used to create many ajax events without adding too many additional functions.

Re: PHP using AJAX INSERT INTO MYSQL

Posted 19 October 2010 - 09:05 PM

what an interesting code snippet, sadly I am the very definition of "beginner" when it comes to AJAX, so I'm scratching my head right now, but I'll save your snippet so I can use it when I finally advance to the rank of "rookie" in terms of using AJAX.

Anyway sir I finally found the problem! The reason it wasn't inserting is because I set the primary key of the record to unique, it is int, and it is not set to auto-increment. My apologies for my stupidity. Anyway thanks so much!

Re: PHP using AJAX INSERT INTO MYSQL

the part with xmlhttp.send(); is the one I'm having trouble with, isnt that the part that I should put in the values I will send to the php file? or am I wrong?

you’re not wrong, you just got the syntax wrong. send() expects 1 parameter which would be equal to PHP’s $_SERVER['QUERY_STRING'] (and of course you still need to follow the Javascript syntax (your code should have thrown an error)). (ref)

Re: PHP using AJAX INSERT INTO MYSQL

Posted 20 October 2010 - 09:29 PM

I have a new problem guys!

How do I make a page load php when I open it? I'm doing a forum, and this is my first time. And can someone point me to a resource where I can learn how to make automatic links for topics in a forum? thanks