471,075 Members | 791 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,075 software developers and data experts.

MySQL use with JavaScript, client side

Hello all !

I am a bluebit in JavaScript.
I would like to write a little program to read data in a MySQL database.
What do I need ?
Is there a specific "JavaScript Include" to make this work ?
Do you have examples or site links to help me ?

Thanks in advance,

Pippin999
Jul 20 '05 #1
4 7177
SuperPippin wrote:
Hello all !

I am a bluebit in JavaScript.
I would like to write a little program to read data in a MySQL database.
What do I need ?
Is there a specific "JavaScript Include" to make this work ?
Do you have examples or site links to help me ?

Thanks in advance,

Pippin999


You can't do that clientside (at least not in plain javascript, you'd have
to use applets/activeX stuff).

--
mvg,
Christophe Vanfleteren
Jul 20 '05 #2
SuperPippin wrote:
Hello all !

I am a bluebit in JavaScript.
I would like to write a little program to read data in a MySQL database.
What do I need ?
Is there a specific "JavaScript Include" to make this work ?
Do you have examples or site links to help me ?

Thanks in advance,

Pippin999

To my knowledge you cannot directly access a MySQL database with
Javascript. What I do is use PHP to pass the database work to the
javascript.

Jul 20 '05 #3

"chotchki" <ch******@mail.usf.edu> schreef in bericht
news:bm**********@news1.usf.edu...
SuperPippin wrote:
Hello all !

I am a bluebit in JavaScript.
I would like to write a little program to read data in a MySQL database.
What do I need ?
Is there a specific "JavaScript Include" to make this work ?
Do you have examples or site links to help me ?

Thanks in advance,

Pippin999

To my knowledge you cannot directly access a MySQL database with
Javascript. What I do is use PHP to pass the database work to the
javascript.


Why not using only PHP....
Jul 20 '05 #4
Ang Talunin wrote:
"chotchki" <ch******@mail.usf.edu> schreef in bericht
news:bm**********@news1.usf.edu...
SuperPippin wrote:
Hello all !

I am a bluebit in JavaScript.
I would like to write a little program to read data in a MySQL database.
What do I need ?
Is there a specific "JavaScript Include" to make this work ?
Do you have examples or site links to help me ?

Thanks in advance,

Pippin999


To my knowledge you cannot directly access a MySQL database with
Javascript. What I do is use PHP to pass the database work to the
javascript.

Why not using only PHP....

You do have a point, here is a sample piece of code Talunin to do it
just in php. Its a stripped down login form try changing the "some*" to
their proper values and trying it out.
Check out www.php.net for more info.

<html>
<head>
<title>Login Page</title>
</head>
<body>
<?php
trim($usernm);
trim($pass);

$db = mysql_connect("localhost", "someuser", "somepassword");

if (!$db)
{
echo "Error: Could not connect to database. Too bad.";
exit;
}

if (!mysql_select_db("somedatabase"))
{
echo "Error: Could not select database. Too bad.";
}
$sql = "select * from sometable where username='".$usernm."'
AND passwd='".$pass."';";
if ($result = mysql_query($sql, $db))
{
if (mysql_fetch_row ( $result))
{
setcookie ("LoginCookie", $usernm);
echo "Authenticated";
}
else
{
echo "<form method=\"post\" target=\"_self\">";
echo " <input type=\"text\" name=\"usernm\" />";
echo " Username";
echo " <input type=\"password\" name=\"pass\" />";
echo " Password";
echo " <input type=\"submit\" value=\"Login\"
name=\"SubmitButton\" />";
echo "</form>";
}
}
?>

Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Terry A. Haimann | last post: by
9 posts views Thread by alonzo | last post: by
3 posts views Thread by Liza | last post: by
2 posts views Thread by RootShell | last post: by
1 post views Thread by mike | last post: by
3 posts views Thread by Mosher | last post: by
7 posts views Thread by Ivan Marsh | last post: by
1 post views Thread by bcochofel | last post: by
4 posts views Thread by =?Utf-8?B?R1ROMTcwNzc3?= | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.