我想让它只有在前一个框中的信息正确时才会出现新的输入框,通过用 mysql_query 检查它我可以修改这段代码吗
function show(id){
if(document.getElementById(id+"-link").style.display=="none") {
document.getElementById(id+"-link").style.display="block";
document.getElementById(id+"-input").style.display="block";
}
}
<tr>
<td><input type="text" id="a1" name="em_1"></td>
<td><a href="#null" onclick="show('b1')">and</a></td>
</tr><tr>
<td><input type="text" id="b1-input" name="em_2" style="display:none"></td>
<td><a href="#null" style="display:none" id="b1-link"</a></td>
</tr><tr>
所以我需要在这里的某个地方添加:
$userCheck=mysql_query(SELECT email FROM users WHERE name = "em_1")
$row=mysql_num_rows($usercheck)
if($row!==0){"show('b1')";}
或有影响的东西,无需刷新页面。这可能吗?
最佳答案
Ajax :
function XMLDoc()
{
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
// xmlhttp.responseText -> return value from php file , so from here you can do your action
}
};
xmlhttp.open("POST","yourfile.php?email={value}",true); // from here send value to check in server side
xmlhttp.send();
}
PHP:
if (isset($_POST['email'])){ // which is variable from `yourfile.php?email`
$userCheck=mysql_query("SELECT email FROM users WHERE name = 'em_1'");
$row=mysql_num_rows($usercheck);
if ($row==0){
echo "no";
} else {
echo "yes";
}
}
传入检查电子邮件是否存在的服务器端脚本的 yourfile
URL,并返回例如是或否 => 然后在 Ajax 的帮助下,它将在当前文档中返回
注意:不要使用mysql
扩展,使用mysqli
或PDO
关于php - 将 mysql_query 添加到 onclick 函数中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14224540/