Fabbry3
29-03-2008, 22:47
Ciao a tuttiiiii!!
Ho un mega problema sul quale mi crogiolo da un paio di giorni. Preciso che sono un niubbastro della programmazione "Server Side" o quell'ostrica che è.
Allora, stavo tranquillamente creando la mia paginetta per modificare un alunno sito in un registro virtuale quando, inspiegabilmente, mi si presenta questo interrogativo. Io ho un form con un menù a tendina dove escono tutti i nominativi degli studenti. Una volta che ne seleziono uno, vorrei che nelle caselle a fianco apparissero i vari dati, estrapolati dal database MySql. Ma quel dannatissimo Javascript sembra non voler proprio funzionare... e io non so che fare!! Vi posto il codice...aiutatemi!!!
<?php
require 'db.inc';
require 'authentication.inc';
$id = $_POST['studente'];
$cognome = $_POST['cognome'];
$nome = $_POST['nome'];
$mail = $_POST['mail'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function ig_onchange(form)
{
alert("Valore della selezione");
alert(form.selezione.selectedIndex);
if (form.selezione.selectedIndex > 0)
{
alert(form.selezione.selectedIndex);
form.cognome.value = "$cognome";
form.nome.value = "$nome";
form.mail.value = "$mail";
}
{
form.cognome.value = "Scelga";
form.nome.value = "uno";
form.mail.value = "studente!";
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Modifica uno Studente</title>
</head>
<body>
<form name="modifica_alunno" action="mod_alunno.php" method="post">
<b>SELEZIONA LO STUDENTE</b>
<fieldset>
<legend> Studente </legend>
<select name="studente">
<option selected="selected"> SCEGLI UNO STUDENTE DA MODIFICARE</option>
<?php
//Recupero i dati dal DB
$strSQL = "SELECT cognome,nome,idstudente FROM users ORDER BY idstudente ASC";
$result = mysql_query($strSQL);
//Visualizzo i records
while ($row = mysql_fetch_assoc($result)){
$IDStudente = $row["idstudente"];
$Anagrafica = $row["cognome"]." ".$row["nome"];
echo "\t<option name=\"selezione\" value=\"$IDStudente\" onClick = \"ig_onchange(this.form)\" >$Anagrafica</option>\n";
}
?>
</select>
<label>Cognome<input name="cognome" type="text" value=" " /></label>
<label>Nome<input name="nome" type="text" value=" "/></label>
<label>E-Mail<input name="mail" type="text" value=" "/></label>
</fieldset>
<input name="submit" type="submit" value="Seleziona" />
</form>
<?
mysql_query("UPDATE users SET cognome = '$cognome', nome = '$nome', email = '$mail' WHERE idstudente = $id");
?>
<?
print "
<TABLE border=1>
<TR>
<TD>Nome</TD>
<TD>Mail</TD>
</TR>
<TR>";
$sqlquery = "SELECT * FROM users WHERE idstudente = '$id'";
$result = mysql_query($sqlquery);
$number = mysql_num_rows($result);
if ($number < 1) {
print " Selezionare un utente per vederne le informazioni ";
}//chiudo l'IF
else{
while ($row = mysql_fetch_array($result)){ //cicla per tutti gli ID presenti nella tabella users
print "<TD>
".$row['cognome']." ".$row['nome']."
</TD>
";
print "
<TD>".$row['email']."</TD>";
print "
</TR>";
} //chiudo il primo while
} //chiudo l'else
print "</TR>
</TABLE>
";
?>
</body>
</html>
Ho un mega problema sul quale mi crogiolo da un paio di giorni. Preciso che sono un niubbastro della programmazione "Server Side" o quell'ostrica che è.
Allora, stavo tranquillamente creando la mia paginetta per modificare un alunno sito in un registro virtuale quando, inspiegabilmente, mi si presenta questo interrogativo. Io ho un form con un menù a tendina dove escono tutti i nominativi degli studenti. Una volta che ne seleziono uno, vorrei che nelle caselle a fianco apparissero i vari dati, estrapolati dal database MySql. Ma quel dannatissimo Javascript sembra non voler proprio funzionare... e io non so che fare!! Vi posto il codice...aiutatemi!!!
<?php
require 'db.inc';
require 'authentication.inc';
$id = $_POST['studente'];
$cognome = $_POST['cognome'];
$nome = $_POST['nome'];
$mail = $_POST['mail'];
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<script type="text/javascript">
function ig_onchange(form)
{
alert("Valore della selezione");
alert(form.selezione.selectedIndex);
if (form.selezione.selectedIndex > 0)
{
alert(form.selezione.selectedIndex);
form.cognome.value = "$cognome";
form.nome.value = "$nome";
form.mail.value = "$mail";
}
{
form.cognome.value = "Scelga";
form.nome.value = "uno";
form.mail.value = "studente!";
}
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Modifica uno Studente</title>
</head>
<body>
<form name="modifica_alunno" action="mod_alunno.php" method="post">
<b>SELEZIONA LO STUDENTE</b>
<fieldset>
<legend> Studente </legend>
<select name="studente">
<option selected="selected"> SCEGLI UNO STUDENTE DA MODIFICARE</option>
<?php
//Recupero i dati dal DB
$strSQL = "SELECT cognome,nome,idstudente FROM users ORDER BY idstudente ASC";
$result = mysql_query($strSQL);
//Visualizzo i records
while ($row = mysql_fetch_assoc($result)){
$IDStudente = $row["idstudente"];
$Anagrafica = $row["cognome"]." ".$row["nome"];
echo "\t<option name=\"selezione\" value=\"$IDStudente\" onClick = \"ig_onchange(this.form)\" >$Anagrafica</option>\n";
}
?>
</select>
<label>Cognome<input name="cognome" type="text" value=" " /></label>
<label>Nome<input name="nome" type="text" value=" "/></label>
<label>E-Mail<input name="mail" type="text" value=" "/></label>
</fieldset>
<input name="submit" type="submit" value="Seleziona" />
</form>
<?
mysql_query("UPDATE users SET cognome = '$cognome', nome = '$nome', email = '$mail' WHERE idstudente = $id");
?>
<?
print "
<TABLE border=1>
<TR>
<TD>Nome</TD>
<TD>Mail</TD>
</TR>
<TR>";
$sqlquery = "SELECT * FROM users WHERE idstudente = '$id'";
$result = mysql_query($sqlquery);
$number = mysql_num_rows($result);
if ($number < 1) {
print " Selezionare un utente per vederne le informazioni ";
}//chiudo l'IF
else{
while ($row = mysql_fetch_array($result)){ //cicla per tutti gli ID presenti nella tabella users
print "<TD>
".$row['cognome']." ".$row['nome']."
</TD>
";
print "
<TD>".$row['email']."</TD>";
print "
</TR>";
} //chiudo il primo while
} //chiudo l'else
print "</TR>
</TABLE>
";
?>
</body>
</html>