MySQL use with JavaScript, client side

S

SuperPippin

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
 
C

Christophe Vanfleteren

SuperPippin said:
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).
 
C

chotchki

SuperPippin said:
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.
 
C

chotchki

Ang said:
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>";
}
}
?>
 

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
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top