Salve, un mio amico mi ha creato un pannello admin in php di un certo servizio.. io non ne so di php ma son il javascript quindi mi sono creato un tasto e gli ho associato l'evento onclick... solamente che li dovrei scrivere nel database nella tabella che si chiama n_partite
Codice PHP:
<?php
error_reporting(E_ALL);
session_start();
include("config.php");
if(!isset($_SESSION['admin'])){
if(!isset($_GET['action'])){
$content='<form action="admin.php?action=login" method="post">Username: <input type="text" name="username" />
Password: <input type="password" name="password" />
<input type="submit" value="Login" /></form>';
}elseif($_GET['action']=="login"){
if($_POST['username']==$username && $_POST['password']==$password){
$_SESSION['admin']=1;
header("Location: admin.php?action=outschedina");
}else{
die("Nome utente o password errati!");
}
}
}elseif($_SESSION['admin'] && !isset($_GET['action'])){
$link=mysql_connect($server,$user,$pass)or die(mysql_error());
$sel_db=mysql_select_db($db,$link)or die(mysql_error());
$query="SELECT * FROM n_partite";
$exec=mysql_query($query,$link)or die(mysql_error());
$temp=mysql_fetch_array($exec);
$part = $temp['num'];
$content='Numero partite: ' . $part . "
";
$content.='<select name="jumpMenu" id="jumpMenu" onclick="numero_di_partite();" onchange="MM_jumpMenu(\'parent\',this,0)">';
for($i=1 ; $i <= 20 ; $i++){
$content.='<option>' . $i . '</option>';
}
$content.='</select>';
$content.='
<input type="button" value="Setta Partite" onclick="settapartite();">';
$content.='<script type="text/javascript">
function settapartite(){
alert("Settare le partite della listbox");
}
</script>';
$content.='<form action="admin.php?action=save" method="post"><table width="600" border="0"><tr>
<th scope="col"></th>
<th scope="col">Squadra in casa</th>
<th scope="col"></th>
<th scope="col">Squadra fuori casa</th>
</tr>';
for($i=1 ; $i <= $part ; $i++){
$content.='<tr>
<th scope="col">' . $i . ' partita</th>
<th scope="col"><input name="' . $i . '_1" type="text"></th>
<th scope="col">vs</th>
<th scope="col"><input name="' . $i . '_2" type="text"></th>
</tr>';
}
$content.='<tr>
<th colspan="4"><input type="submit" value="Crea schedina"></th>
</tr>
</table>
</form>';
}elseif($_SESSION['admin'] && $_GET['action']=="save"){
$partite=array();
foreach($_POST as $k => $v){
$loc=explode("_",$k);
$partite[$loc[0]][$loc[1]]=$v;
}
$link=mysql_connect($server,$user,$pass)or die(mysql_error());
$sel_db=mysql_select_db($db,$link)or die(mysql_error());
foreach($partite as $k => $v){
$query="UPDATE partite SET squadra1='" . $v[1] . "', squadra2='" . $v[2] . "' WHERE pid=" . $k;
$exec=mysql_query($query,$link)or die(mysql_error());
}
mysql_close($link);
header("Location: admin.php?action=outschedina");
}elseif($_SESSION['admin'] && $_GET['action']=="outschedina"){
$content='<table width="600" border="0"> <tr>
<th scope="col"></th>
<th scope="col">Squadra in casa</th>
<th scope="col"></th>
<th scope="col">Squadra fuori casa</th>
</tr>';
$link=mysql_connect($server,$user,$pass)or die(mysql_error());
$sel_db=mysql_select_db($db,$link)or die(mysql_error());
$query="SELECT * FROM n_partite";
$exec=mysql_query($query,$link)or die(mysql_error());
$temp=mysql_fetch_array($exec);
$part = $temp['num'];
$query="SELECT * FROM partite";
$exec=mysql_query($query,$link)or die(mysql_error());
$conta=1;
echo 'Numero partite: ', $part, "\n";
while($conta <= $part){
$temp=mysql_fetch_array($exec);
$content.='<tr><th scope="col">' . $conta . ' partita</th>
<th scope="col">' . $temp['squadra1'] . '</th>
<th scope="col">vs</th>
<th scope="col">' . $temp['squadra2'] . '</th></tr>';
$conta++;
}
$content.='<tr><th scope="col">[url="admin.php"]Modifica[/url]</table>';
mysql_close($link);
}
?>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Amministrazione</title>
</head>
<body>
<?=$content?>
</body>
</html>
Come faccio? Qualcuno ha una soluzione?