Page 1 of 1

Javascript with MYSQL

Posted: Mon Nov 22, 2004 10:20 pm
by winsonlee

Code: Select all

<script language="JavaScript"> 
<!--hide  
var yourname= prompt('Please enter your name', ' ');

//--> 
</SCRIPT>

Is it possible to use the following script to store the name in the mysql database ??

Posted: Mon Nov 22, 2004 10:37 pm
by magicrobotmonkey
i dont believe javascript can directly connect to a database.
If you are asking if you can pass the yourname variable to php and then use php's database connectivity to store the information, then yes, you can.

Posted: Mon Nov 22, 2004 10:54 pm
by andre_c
actually, there's no direct way to pass a javascript variable to php.
the closest thing is to change the location of the page with javascript to an address containing the variable in the query string, and then grabbing the value of the variable with $_REQUEST or $_GET
or changing the value of a hidden field and submiting a form using javascript.

Posted: Tue Nov 23, 2004 1:06 am
by winsonlee
sounds abit complicated. Any idea how i can change the location of the page with javascript to an address containing the variable in the query string ??

Posted: Tue Nov 23, 2004 3:15 am
by phpScott

Code: Select all

<script language="JavaScript">
<!--hide 
var yourname= prompt('Please enter your name', ' ');
document.formname.passYourName.value=yourname;

document.formname.submit();
//-->
</SCRIPT>

Code: Select all

<form name="formname" action="pageToRedirectTo.php" method="post">
<input type="hidden" name="passYourName" value="" />
</form>
get the yourname then set a hidden input field in your form then submit the form

phpScott