Javascript & MySQL
Posted: Mon Aug 12, 2002 7:06 am
someone knows like making in order to approach of the MySql tables from a Javascript?
thanks
have a good day
thanks
have a good day
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
function myJavaScriptFunc()
myVar = "<? echo $phpvariable; ?>";
alert(myVar);
}Code: Select all
<html>
<?php
function doFrameset()
{ ?>
<frameset rows="*,50">
<frame src="test.php" name="fForm">
<frame src="about:" name="fDesc">
</frameset>
<?php
}
function doDescription()
{
print('<body>description of '.$_POSTї'cod'].' is ...</body>');
}
function doQuery()
{
print('performing '.$_POSTї'cod'].'...');
}
function doForm()
{ ?>
<head><script language="JavaScript">
function doSearch()
{
form3.mode.value = "search";
form3.target="fDesc";
form3.submit();
}
function doSubmit()
{
form3.mode.value = "perform";
form3.target="fForm";
form3.submit();
}
</script></head>
<body>
<form name="form3" method="post">
<input type="hidden" name="mode" value="" />
<input type="text" name="cod" value="123" maxlength="3" size="3" onChange="doSearch();" />
<br/>
<button onClick="doSubmit();">submit</button>
</form>
<?php
}
if (isset($_POSTї'mode']))
{
if ($_POSTї'mode']=='search')
doDescription();
else
{
doForm();
doQuery();
print('</body>');
}
}
else
{
doForm();
print('</body>');
}
?>
</html>Code: Select all
<html>
<head>
<applet width="0" height="0" name="Query" code="Query" codebase="">
</applet>
<script language="JavaScript">
<!--
function loadField(fname,codname,desname, submit) {
stat = false;
f_name = documentїfname]
sql = "select xxxx from yyyy where zzz = '"+f_nameїcodname].value+"'"
myConn = "jdbc:mysql://localhost/database?user=user&password=passwd"
field = "desc"
ret = document.Query.setString(sql, field, myConn)
if (ret != "N")
f_nameїdesname].value = ret
if (ret == "N") { //record not found
alert("Not inserted")
f_nameїcodname].focus()
stat = true
}
f_nameїsubmit].disabled = stat
}
// -->
</script>
</head>
<body>
<form name="form1" method="post">
<input type="text" name="ali" value="" maxlength="3" size="3" onChange="loadField('form1','ali','desc','Invia');"/>
<input type="text" name="desc" value="" maxlength="100" size="100" onFocus="this.blur();document.form1.Invia.focus();"/>
<input type="submit" name="Invia" value="Conferma">
</form>
</body>
</html>Code: Select all
import java.applet.Applet;
import java.sql.*;
public class Query extends Applet {
String myConn;
String text;
public void init() {
text = new String("Ciao");
}
public String setString(String sql, String field, String myConn) {
text = "N";
try {
Class.forName("org.gjt.mm.mysql.Driver");
}
catch(Exception ex) {
text = "Can't find Database driver class: " + ex;
return text;
}
try {
Connection con = (Connection) DriverManager.getConnection(myConn);
Statement stmt = (Statement) con.createStatement();
ResultSet rs = (ResultSet) stmt.executeQuery(sql);
while (rs.next()) {
text = rs.getString(field);
}
stmt.close();
con.close();
}
catch(SQLException ex) {
text = "SQLException: " + ex;
}
return text;
}
}