Javascript with MYSQL

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
winsonlee
Forum Commoner
Posts: 76
Joined: Thu Dec 11, 2003 8:49 pm

Javascript with MYSQL

Post 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 ??
magicrobotmonkey
Forum Regular
Posts: 888
Joined: Sun Mar 21, 2004 1:09 pm
Location: Cambridge, MA

Post 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.
User avatar
andre_c
Forum Contributor
Posts: 412
Joined: Sun Feb 29, 2004 6:49 pm
Location: Salt Lake City, Utah

Post 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.
winsonlee
Forum Commoner
Posts: 76
Joined: Thu Dec 11, 2003 8:49 pm

Post 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 ??
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post 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
Post Reply