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