I'm writing a page in php (index.php, say) which uses an external php script (do.php, say) called through the jQuery $.post
function.
I am passing a post variable called doit which determines what the script will do. For example, if doit is 1, it assigns an unique id to the user and stores it in a cookie called uid with the setcookie() function. If doit is 2, it inputs another post data called msg into a table, that it creates by the name t+uid. Eg. If uid is 14, it creates a table called t14 and puts msg in it.
I use the following line of code to set the cookie:
setcookie("uid", $val, time()+3600, '/');
And this line of code to create the table:
$q = "create table t".$_COOKIE["uid"]." (sl int primary key auto_increment, msg varchar(1000), seen int);";
mysql_query($q);
Now my problem is this: The sql query is executed correctly, but I dont get any value from the cookie variable. The table created is simply named t.
My question is: What am I doing wrong? What should I do so that I get a value correctly?
P.S: When I check the cookies set by my page, I see the cookie there. I tried clearing the cookies and trying again, but each time, the cookie is set correctly, but not the table.
There is also another problem. The sql queries are executed only after i refresh the page. For example, I have another table called uu in which I store the uid of the current user and some other info. The last row in that table contains the previous uid and not the present one. If uid is 10 this time, and i refresh the page and get uid as 11, only then does the info for uid = 10 is updated in the table uu.
Any help at all is greatly appreciated :-) Thanks.