how to get a javascript function value stored in a database using php---really imp.

G

garima puri

hi
thanks a lot for answering my other queries fast
my problem is ihad a javascript function in which many values are
returned in one variable.
now after it i want that the return values must be insert into the
database by using php.
can anyone tell me how can i sand a javascript function return value to
a databse of mysql
eg
<script>
function() {
x = //(values)
return(x)
}
</script>
now x must be in databse,how


DNT WORRY FROM PROBLEMS
 
E

Erwin Moller

garima said:
hi
thanks a lot for answering my other queries fast
my problem is ihad a javascript function in which many values are
returned in one variable.
now after it i want that the return values must be insert into the
database by using php.
can anyone tell me how can i sand a javascript function return value to
a databse of mysql
eg
<script>
function() {
x = //(values)
return(x)
}
</script>
now x must be in databse,how


DNT WORRY FROM PROBLEMS

Hi garima,

Well, Javascript executes on a clients browser, and your database in on some
server.
So if you produced some data with Javascript , you must send that to a PHP
script on your server. This PHP script inserts it into some database,
right?

You could do this in several ways, the most simple solution is using a
hidden frame, post the data to there.

something like this:
function iPostToPHP(somevalue) {
var newURL = "http://www,mysite.com/mydbinserter.php";
newURL += "?somevalue="+somevalue;
// set new adres.
parent.frames.myhiddenframe.location = newURL;
}

from mydbinserter.php:
$somevalue = $_GET["somevalue"];
// do insert here


Of course my examplesetup is utterly unsafe. Anyone can send values to the
script, so you might implement some extra stuff, like some session-logic.

Also my example only sends 1 single value, you should adept it to send more
values, like this:
mydbinserter.php?value1=bla&value2=bladibla&value3=yeah

Futhermore, use the escape function in JS when you create URL's that might
contain funky characters in the name/value pairs.

Good luck.

Regards,
Erwin Moller
 
J

Joakim Braun

garima puri said:
hi
thanks for answering
can u tell me,what is:

function iPostToPHP(somevalue) {
var newURL = "http://www,mysite.com/mydbinserter.php";
newURL += "?somevalue="+somevalue;
// set new adres.
parent.frames.myhiddenframe.location = newURL;
}

"http://www,mysite.com/mydbinserter.php";-----what is this

It's a PHP document called mydbinserter.php. He's left that for you to
write.
ihave many value in URL
how can i sant the x,return value to databse
can u explain more

A query string consists of name=value pairs separated by "&". You need to
convert whatever it is your javascript function returns to this string-based
format. Server-side, you make a PHP document which harvests the values of
the query string component of the URL, then uses whatever method is suitable
to communicate with your database and insert the desired values into the
appropriate table (for MySQL, the SQL statement to execute might look
something like "INSERT INTO someTable VALUES ('Blah','Blah');"). This is not
a javascript question. You may find your PHP and MySQL documentation
helpful.
 
E

Erwin Moller

garima said:
hi
thanks for answering
can u tell me,what is:

function iPostToPHP(somevalue) {
var newURL = "http://www,mysite.com/mydbinserter.php";
newURL += "?somevalue="+somevalue;
// set new adres.
parent.frames.myhiddenframe.location = newURL;
}

"http://www,mysite.com/mydbinserter.php";-----what is this

That is the name of a PHP script I conjured up.
I just made it up.
YOU have to write that script.
Javascript cannot access the database on your server directly, so you need a
PHP script as an intermediate, passing the values from your JS to the
database.

Regards,
Erwin Moller
 
E

Erwin Moller

Joakim said:
It's a PHP document called mydbinserter.php. He's left that for you to
write.


A query string consists of name=value pairs separated by "&". You need to
convert whatever it is your javascript function returns to this
string-based format. Server-side, you make a PHP document which harvests
the values of the query string component of the URL, then uses whatever
method is suitable to communicate with your database and insert the
desired values into the appropriate table (for MySQL, the SQL statement to
execute might look something like "INSERT INTO someTable VALUES
('Blah','Blah');"). This is not a javascript question. You may find your
PHP and MySQL documentation helpful.

Thanks Joakim. :)

I have nothing to add to that explanation. :)

Good luck Garima.

Oh, one warning: Maybe I am wrong, if so forgive me, but I have the
impression you are learning Javascript, PHP, and SQL all at the same time.
That might be a little too much to grok all at the same time without
guidance.
Maybe it is better to master PHP and SQL-queries to your database first, and
when you feel confartable with that: then start with Javascript passing
stuff to your PHP script.


Regards,
Erwin Moller
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top