Codice PHP:
<?php require_once('Connections/Mysql.php'); ?>
<?php
$currentPage = $HTTP_SERVER_VARS["PHP_SELF"];
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}
if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO Formazioni (Giornata, Squadra, Giocatore, Punti) VALUES (%s, %s, %s, %s)",
GetSQLValueString($HTTP_POST_VARS['Giornata'], "text"),
GetSQLValueString($HTTP_POST_VARS['Squadra'], "text"),
GetSQLValueString($HTTP_POST_VARS['Giocatore'], "text"),
GetSQLValueString($HTTP_POST_VARS['Punti'], "text"));
mysql_select_db($database_Mysql, $Mysql);
$Result1 = mysql_query($insertSQL, $Mysql) or die(mysql_error());
}
$colname_Recordset1 = "1";
if (isset($HTTP_SERVER_VARS[' '])) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? $HTTP_SERVER_VARS[' '] : addslashes($HTTP_SERVER_VARS[' ']);
}
mysql_select_db($database_Mysql, $Mysql);
$query_Recordset1 = sprintf("SELECT * FROM Formazioni WHERE Giornata = '%s'", $colname_Recordset1);
$Recordset1 = mysql_query($query_Recordset1, $Mysql) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
$queryString_Recordset1 = "";
if (!empty($HTTP_SERVER_VARS['QUERY_STRING'])) {
$params = explode("&", $HTTP_SERVER_VARS['QUERY_STRING']);
$newParams = array();
foreach ($params as $param) {
if (stristr($param, "pageNum_Recordset1") == false &&
stristr($param, "totalRows_Recordset1") == false) {
array_push($newParams, $param);
}
}
if (count($newParams) != 0) {
$queryString_Recordset1 = "&" . implode("&", $newParams);
}
}
$queryString_Recordset1 = sprintf("&totalRows_Recordset1=%d%s", $totalRows_Recordset1, $queryString_Recordset1);
?>
<html>
<head>
<title>Documento senza titolo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="Body.css" rel="stylesheet" type="text/css">
</head>
<body>
<p> </p>
<form name="form2" method="post" action="">
<p>
<select name="select">
<option value="1">1 Giornata</option>
<option value="2">2 Giornata</option>
<option value="3">3 Giornata</option>
</select>
<input name="Aggiorna" type="submit" id="Aggiorna" value="Invia">
<?php
$colname_Recordset1 = "0";
if (isset(0)) {
$colname_Recordset1 = (get_magic_quotes_gpc()) ? 0 : addslashes(0);
}
mysql_select_db($database_Mysql, $Mysql);
$query_Recordset1 = sprintf("SELECT * FROM Formazioni WHERE Giornata = '%s'", $colname_Recordset1);
$Recordset1 = mysql_query($query_Recordset1, $Mysql) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
</p>
<p> </p>
<table width="476" border="1">
<tr>
<td width="330"> </td>
<td width="130"> </td>
</tr>
<tr>
<td><?php echo $row_Recordset1['Giocatore']; ?></td>
<td><?php echo $row_Recordset1['Punti']; ?></td>
</tr>
</table>
</form>
<p> </p>
<p> </p>
<form method="post" name="form1" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td nowrap align="right">Giornata:</td>
<td><input type="text" name="Giornata" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Squadra:</td>
<td><input type="text" name="Squadra" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Giocatore:</td>
<td><input type="text" name="Giocatore" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Punti:</td>
<td><input type="text" name="Punti" value="" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right"> </td>
<td><input type="submit" value="Inserisci record"></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1">
</form>
<p> </p>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
Vorrei visualizzare solo i recordset di una giornata specifica, ma quando scelgo la giornata nel menu e do la conferma con il pulsante, mi viene ricaricata la stessa pagina con gli stessi dati.
FunCool: Quando scrivi del codice, inseriscilo tra i tag appositi. Modifico il titolo.