HTML页面:http://imgur.com/P95CyMv,VV4QYKS,xOE8RVA
id = 1的数据库行:http://imgur.com/P95CyMv,VV4QYKS,xOE8RVA#1
当我点击第一个表格的提交按钮时,我想在第二个表格的文本框中显示id = 1的值。
例如:http:// imgur.com / P95CyMv,VV4QYKS,xOE8RVA#2(不含空格)
我这样做,并且在工作前几个小时,但是我做了一些事情而现在还没有工作。
HTML / PHP:
<form method="post">
<p>Mostrar evento por:</p>
<p>
<select name="select" id="select">
<option selected="selected">id</option>
<option>Nome do Evento</option>
<option>Data do Evento</option>
</select>
</p>
<p>
<input type="text" name="nomeEvento" id="text" width="300">
</p>
<?php
require ('sql_connect.php');
if (isset($_POST['submit'])){
$selectedItem = mysql_escape_string($_POST['select']);
$nomeEvent = mysql_escape_string($_POST['nomeEvento']);
if (!$_POST['select'] | !$_POST['nomeEvento'])
{
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Tem de meter um username e uma password')
window.location.href='UpdateEvents.php'
</SCRIPT>");
exit();
}
$query = "select * from `eventos` where `$selectedItem` = '$nomeEvent'";
$result = mysql_query($query);
if (!$result) die ("Database access failed: " . mysql_error());
while($row = mysql_fetch_array($result))
{
$coiso1 = $row['nome'];
$coiso2 = $row['data'];
$coiso3 = $row['descricao'];
$coiso4 = $row['url'];
}
echo $selectedItem, $nomeEvent, $coiso1, $coiso2, $coiso3;
}
?>
<p>
<input type="button" name="Button" value="Mostrar" onClick="NomeEvento('<?php echo $coiso1 ?>','<?php echo $coiso2 ?>', '<?php echo $coiso3 ?>');">
</p>
</form>
<form method="get">
<p>Nome do Evento:</p>
<p>
<input name="text1" type="text" id="text1" width="300">
</p>
<p>Data do Evento:</p>
<p>
<input type="text" name="text" id="text2" width="300">
</p>
<p>Descrição:</p>
<p>
<input type="text" name="text2" id="text3" width="300">
</p>
<p>
<input type="submit" name="submit2" value="Alterar">
</p>
</form></p>>
JAVASCRIPT FUNCTION:
<script>
function NomeEvento(nomeEvento, dataEvento, descricaoEvento)
{
document.getElementById("text1").value= nomeEvento;
document.getElementById("text2").value= dataEvento;
document.getElementById("text3").value= descricaoEvento;
}
</script>
有人可以帮助我吗?
答案 0 :(得分:0)
目前,当您点击提交按钮时,您没有$coiso1
,$coiso2
和$coiso3
个变量,因为您的php脚本只会在POST请求中填充它。
尝试在页面加载时调用方法NomeEvento(var1, var2, var3)
。