Hi all... surely someone will be able to solve my stupid problem...
I have a table name risultati1 (results) with the following fields:
id_match
week
id_c (id of the team playing home)
id_f (id of the team playing away)
g_c (points scored by the home team)
g_f (points scored by the away team)
every week I have 4 matches and I would like to update all the results together without doing it separately...
this is the form I have created with a FIX week for trying purposal (it will become a variable)
<?
include("dbinfo.inc.php" );
$db = mysql_connect("localhost", "$dbuser", "" ) or die("Problem connecting" );
mysql_select_db("$dbname",$db)or die("Problem selecting database" );
$result = mysql_query("SELECT * FROM risultati1 WHERE week='24'",$db);
echo "<table width='100%' border='1' cellpadding='0' cellspacing='0' bordercolor='#9999CC' class='risultati' background='Images/prova2.jpg'>\n";
echo "<tr bgcolor='#99CCFF'>\n";
echo "<td colspan='4'><div align='center'><strong><font color='#000000' face='Arial, Helvetica, sans-serif'>Risultati</font></strong></div></td>\n";
while($myrow = mysql_fetch_array($result))
{
$id_match = $myrow["id_match"];
$week = $myrow["week"];
$id_c = $myrow["id_c"];
$id_f = $myrow["id_f"];
$g_c = $myrow["g_c"];
$g_f = $myrow["g_f"];
echo "<FORM METHOD=GET ACTION=\"ins_risultati.php\">";
include("risultati.inc.php" );
echo "<tr bordercolor='#9999CC'>\n";
echo "<td>$id_c</td>\n";
echo "<td>$id_f</td>\n";
echo "<td ><INPUT TYPE=\"TEXT\" NAME=\"g_c\" VALUE=\"$g_c\" SIZE=\"4\"></td>\n";
echo "<td><INPUT TYPE=\"TEXT\" NAME=\"g_f\" VALUE=\"$g_f\" SIZE=\"4\"></td>\n";
}
echo "</TABLE>\n";
$id_c=(urlencode($id_c));
$id_f=(urlencode($id_f));
echo "<INPUT TYPE=\"HIDDEN\" NAME=\"id_match\" VALUE=$id_match>";
echo "<INPUT TYPE=\"HIDDEN\" NAME=\"id_c\" VALUE=$id_c>";
echo "<INPUT TYPE=\"HIDDEN\" NAME=\"id_f\" VALUE=$id_f><BR>";
echo "<INPUT TYPE=SUBMIT VALUE=\"Inserisci i risultati\">";
?>
and this is the ins_risultati.php file
<?
include("dbinfo.inc.php");
$db = mysql_connect("localhost", "$dbuser", "") or die("Problem connecting");
mysql_select_db("$dbname",$db)or die("Problem selecting database");
$id_c=(urldecode($id_c));
$id_f=(urldecode($id_f));
$sql="UPDATE risultati1 SET g_c='$_GET[g_c]', g_f='$_GET[g_f]' WHERE id_match='$_GET[id_match]'";
$result = mysql_query($sql) or die(mysql_error());
if(mysql_affected_rows($result) == -1) {
echo "The database didn't get updated";
} else {
echo "The database got updated successfully"<BR>;
echo " You updated:$result fields";
}
?>
This is what happen:
-I only update the LAST match (last of 4)
-The names have a "+" instead of spaces
I receive this message on the screen:
Warning: mysql_affected_rows(): supplied argument is not a valid MySQL-Link resource in c:\programmi\easyphp\www\lf\ins_risultati.php on line 22
The database got updated successfully: 1
and finally this is the URL I have in the browser:
notebook/LF/ins_risultati.php?g_c=2&g_f=3&g_c=0&g_f=0&g_c=4&g_f=4&g_c=0&g_f=0&id_match=96&id_c=AS%252BPilarella&id_f=Ciao%252BWena
as you can see I have the 8 scores but only 1 ID_match and one match team names...
how can I solve my update ???
thanx for your help
Roberto