I can't tell whether your AJAX will work or not, but your PHP page won't do what you want.
Remember to test your PHP pages themselves before calling them with AJAX, so that you can debug them easier. For example, you could easily go to http://localhost/p.php?action=add&name=Dan
That would make sure that the script is going to work, which I bet it doesn't. The reason? You seem to have echo statements dotted around everywhere. You only use echo if you want to output something, you have it on your first line where it isn't needed (you're also missing a semi-colon at the end of this line). Change your code to this and see whether it works:
<?php
$action = $_GET['action'];
switch ($action) {
case 'add':
add();
default:
}
function add() {
$link = mysql_connect('locahost','root','root');
mysql_select_db('test');
$sql = " INSERT INTO 'user'(name) VALUES('". $_GET['name'] ."') ";
mysql_query($sql, $link);
echo '1';
}
?>
Remember: check the page on its own first rather than calling it via AJAX, that way you will get any errors that PHP produces.