我打算做的是一个对话框会提示,用户将输入他的用户名,当单击确定时,javascript函数mySearch中的php代码将在mysql中获取他的详细信息并将其显示在文本框中。帮助。T_T 不行。
<script>
function mySearch()
{ var name = prompt("Search","Enter username");
if (name!=null && name!="")
{
var sentval = document.getElementById("sentval");
sentval.value = name;
<?php
$myLink = mysql_connect('localhost','root', '1234') or die(mysql_error());
$selectDB = mysql_select_db('proj2db', $myLink) or die(mysql_error());
$sql = "SELECT * FROM userTBL WHERE uName ='".$_POST['sentval']."'";
$exec = mysql_query($sql, $myLink);
$row = mysql_fetch_array($exec);
$uname = $row['uName'];
$pwd = $row['pwd'];
$code = $row['sAns'];
$link = $row['path'];
?>
}
}
</script>
</head>
<body>
<form method="post" action="" name="myform" id="myform">
<input type="hidden" id="sentval"/>
<center>
<table>
<tr>
<td><font face="Tahoma" size = "2" color="#0B3861">Username:  </font></td>
<td>
<input type = "text" id = "uname" name = "uname" size="35" value="<?php echo $uname ?>"/>
<button type="button" style="height: 25px; width: 60px" onclick="mySearch()">Search</button>
</td>
</tr>
<tr>
<td><font face="Tahoma" size = "2" color="#0B3861">Password:  </font></td>
<td><input type = "password" id = "pwd" name = "pwd" size="35" value="<?php echo $pwd ?>"/></td>
</tr>
<tr>
<td><font face="Tahoma" size = "2" color="#0B3861">Re-type Password:  </font></td>
<td><input type = "password" id = "repwd" name = "repwd" size="35" value="<?php echo $pwd ?>"/></td>
</tr>
<tr>
<td><font face="Tahoma" size = "2" color="#0B3861">Code:  </font></td>
<td><input type = "text" id = "code" name = "code" size="35" value="<?php echo $code ?>"/></td>
</tr>
<tr>
<td><font face="Tahoma" size = "2" color="#0B3861">Link:  </font></td>
<td><input type = "text" id = "link" name = "link" size="35" value="<?php echo $link ?>"/></td>
</tr>
<tr>
<td colspan=2 align="right">
<font face="Tahoma" size = "2" color="#0B3861">(e.g. http://www.google.com or index.php)</font>
</td>
</tr>
<tr>
<td colspan=2 align="right">
<input type="submit" name="submit" value="Save" style="height: 25px; width: 60px"/>
<button type="button" style="height: 25px; width: 60px" onclick="location.href='adminMain.php'">Cancel</button>
</td>
</tr>
</table>
</center>
</form>
</body>
<?php
if (!empty($_POST['uname']) && !empty($_POST['pwd']) && !empty($_POST['repwd']) && !empty($_POST['code']) && !empty($_POST['link']))
{
if ($_POST['pwd'] == $_POST['repwd'])
{
$myLink = mysql_connect('localhost','root', '1234') or die(mysql_error());
$selectDB = mysql_select_db('proj2db', $myLink) or die(mysql_error());
$sql = "UPDATE `proj2db`.`usertbl` SET pwd='".$_POST['pwd']."', sAns='".$_POST['code']."', path='".$_POST['link']."' WHERE uName='".$_POST['uname']."';";
$exec = mysql_query($sql, $myLink);
}
else
echo "<font face='Tahoma' size = '2' color='red'><center>Error: Password mismatched <br> Press cancel to return to home page </center></font>";
}
?>