Page 3 of 5
Re: Upload a file
Posted: Tue Nov 11, 2008 7:23 pm
by infolock
It's because you are missing a curly brace at the end to close the last else statement. Right now you only have 2 at the end, make it 3 and it will work. Thus why proper indention pays off

Re: Upload a file
Posted: Tue Nov 11, 2008 7:35 pm
by John Cartwright
It's also helpful to post error messages or output, instead of saying it simply isn't working

Re: Upload a file
Posted: Wed Nov 12, 2008 2:02 am
by mmj
Code: Select all
mysql_close();
if ($winner == $player1) {
$result = mysql_query("SELECT * FROM player_stats WHERE name='$player1'") or die(mysql_error());
If you use mysql_close then you have to open it again.
Just put mysql_close at the end of the script.
Re: Upload a file
Posted: Wed Nov 12, 2008 5:40 pm
by Aravinthan
It gives me this error:
Game 13 has been successfully inserted into the database. Details:
GameId: 13
Player1: 36Drew
Player2: Sporting_Lisbon
Winner:Sporting_Lisbon
Map:
Access denied for user 'aoe3clan'@'localhost' (using password: NO)
Meaning that the game was inserted but the players weren't updated....
Re: Upload a file
Posted: Wed Nov 12, 2008 7:36 pm
by Syntac
Looks like your authentication failed.
Re: Upload a file
Posted: Thu Nov 13, 2008 5:34 pm
by Aravinthan
Yeah but, I used the same connection for the both, I jsut changed the database name....
Re: Upload a file
Posted: Thu Nov 13, 2008 6:56 pm
by Aravinthan
OK I have been able to fix that error, but My file isnt getting uploaded to my mysql tables:
Code: Select all
<?php
$gameid = $_POST['gameid'];
$player1 = $_POST['player1'];
$player2 = $_POST['player2'];
$winner = $_POST['winner'];
$fileName= $player1 . ' vs ' . $player2 . ' on ' . $map;
$tmpName = $_FILES['file']['tmp_name'];
$fileSize = $_FILES['file']['size'];
$fileType = $_FILES['file']['type'];
$link = mysql_connect ("localhost", "user", "pass") or die(mysql_error());
mysql_select_db("aoe3clan_division1") or die(mysql_error());
$sql="SELECT COUNT(*) AS count
FROM games
WHERE gameid='$gameid'";
$result=mysql_query($sql);
$row=mysql_fetch_assoc($result);
if ($row['count']>0){
echo "There is already a game with this id. <a href='http://www.aoe3clan.com'>Home</a>";
}
else {
mysql_query("INSERT INTO games (gameid, player1, player2, winner, map) VALUES ('$gameid', '$player1', '$player2', '$winner', '$map')") or die(mysql_error());
print "Game $gameid has been successfully inserted into the database. Details:</br>GameId: $gameid</br> Player1: $player1</br> Player2: $player2</br> Winner:$winner</br> Map:$map</br>";
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
include 'library/config.php';
include 'library/opendb.php';
$query = "INSERT INTO upload (name, size, type, content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
mysql_query($query) or die('Error, query failed');
include 'library/closedb.php';
echo "File $fileName uploaded<br>";
This is what I get:
Game 653 has been successfully inserted into the database. Details:
GameId: 653
Player1: 36Drew
Player2: Sporting_Lisbon
Winner:Sporting_Lisbon
Map:
File 36Drew vs Sporting_Lisbon on uploaded
36Drew has successfully received 1 points. View the Ladder
Sporting_Lisbon has successfully received 3 points. View the Ladder
Normally the file should be uploaded but I when I try to output all the files:
Code: Select all
mysql_select_db ("aoe3clan_division1", $link);
$Result = mysql_query("SELECT * FROM upload where name like '36Drew' order by id DESC",$link)
or die(mysql_error());
while ($Row = mysql_fetch_row($Result))
{
printf ("<tr><td align='center'>%s</td><td align='center'>%s</td><td align='center'>%s</td></tr>",
$Row[0], $Row[1], $Row[3]);
}
?>
There is nothing that gets displayed....
Re: Upload a file
Posted: Fri Nov 14, 2008 2:38 pm
by mmj
You shouldn't be using addslashes.
Post all of the current code.
Re: Upload a file
Posted: Fri Nov 14, 2008 4:59 pm
by Aravinthan
Ok here it is:
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<HTML>
<HEAD>
<TITLE>Player Updated</TITLE>
<META NAME="Generator" CONTENT="TextPad 4.6">
<META NAME="Author" CONTENT="?">
<META NAME="Keywords" CONTENT="?">
<META NAME="Description" CONTENT="?">
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#FF0000" VLINK="#800000" ALINK="#FF00FF" BACKGROUND="?">
<?php
ini_set("display_errors", 1);
$gameid = $_POST['gameid'];
$player1 = $_POST['player1'];
$player2 = $_POST['player2'];
$winner = $_POST['winner'];
$fileName= $player1 . ' vs ' . $player2 . ' on ' . $map;
$tmpName = $_FILES['file']['tmp_name'];
$fileSize = $_FILES['file']['size'];
$fileType = $_FILES['file']['type'];
$link = mysql_connect ("localhost", "user", "pass") or die(mysql_error());
mysql_select_db("aoe3clan_division1") or die(mysql_error());
$sql="SELECT COUNT(*) AS count
FROM games
WHERE gameid='$gameid'";
$result=mysql_query($sql);
$row=mysql_fetch_assoc($result);
if ($row['count']>0){
echo "There is already a game with this id. <a href='http://www.aoe3clan.com'>Home</a>";
}
else {
mysql_query("INSERT INTO games (gameid, player1, player2, winner, map) VALUES ('$gameid', '$player1', '$player2', '$winner', '$map')") or die(mysql_error());
print "Game $gameid has been successfully inserted into the database. Details:</br>GameId: $gameid</br> Player1: $player1</br> Player2: $player2</br> Winner:$winner</br> Map:$map</br>";
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
include 'library/config.php';
include 'library/opendb.php';
$query = "INSERT INTO upload (name, size, type, content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
mysql_query($query) or die('Error, query failed');
include 'library/closedb.php';
echo "File $fileName uploaded<br>";
echo $size;
echo $type;
if ($winner == $player1) {
$result = mysql_query("SELECT * FROM player_stats WHERE name='$player1'") or die(mysql_error());
while($row = mysql_fetch_array( $result )) {
$oldp1 = $row['points'];
$newp1 = '3';
$point = $oldp1 + $newp1;
$oldgp1 = $row['gp'];
$newgp1 = '1';
$gp = $oldgp1 + $newgp1;
$oldwins1 = $row['wins'];
$newwins1 = '1';
$wins1 = $oldwins1 + $newwins1;
mysql_query("UPDATE player_stats SET points='$point', gp='$gp', wins='$wins1' WHERE name='$player1'") or die(mysql_error());
print "$player1 has successfully received $newp1 points.";
}
$result = mysql_query("SELECT * FROM player_stats WHERE name='$player2'") or die(mysql_error());
while($row = mysql_fetch_array( $result )) {
$oldp2 = $row['points'];
$newp2 = '1';
$point = $oldp2 + $newp2;
$oldgp2 = $row['gp'];
$newgp1 = '1';
$gp = $oldgp1 + $newgp1;
$oldloss2 = $row['loss'];
$newloss2 = '1';
$loss2 = $oldloss2 + $newloss2;
mysql_query("UPDATE player_stats SET points='$point', gp='$gp', defeats='$loss2' WHERE name='$player2'") or die(mysql_error());
print "$player2 has successfully received $newp2 points. ";
}
}else {
$result = mysql_query("SELECT * FROM `player_stats` WHERE name='$player1'") or die(mysql_error());
while($row = mysql_fetch_array( $result )) {
$oldp1 = $row['points'];
$newp1 = '1';
$point = $oldp1 + $newp1;
$oldgp1 = $row['gp'];
$newgp1 = '1';
$gp = $oldgp1 + $newgp1;
$oldloss1 = $row['defeats'];
$newloss1 = '1';
$loss1 = $oldloss1 + $newloss1;
mysql_query("UPDATE player_stats SET points='$point', gp='$gp', defeats='$loss1' WHERE name='$player1'") or die(mysql_error());
print "$player1 has successfully received $newp1 points. <a href='http://www.aoe3clan.com/test/ladder.php'> View the Ladder</a>";
}
$result = mysql_query("SELECT * FROM player_stats WHERE name='$player2'") or die(mysql_error());
while($row = mysql_fetch_array( $result )) {
$oldp2 = $row['points'];
$newp2 = '3';
$point = $oldp2 + $newp2;
$oldgp2 = $row['gp'];
$newgp2 = '1';
$gp = $oldgp2 + $newgp2;
$oldwins2 = $row['wins'];
$newwins2 = '1';
$wins2 = $oldwins2 + $newwins2;
mysql_query("UPDATE player_stats SET points='$point', gp='$gp', wins='$wins2' WHERE name='$player2'") or die(mysql_error());
print "</br>$player2 has successfully received $newp2 points. <a href='http://www.aoe3clan.com/test/ladder.php'> View the Ladder</a>";
}
}
}
mysql_close();
?>
</BODY>
</HTML>
Re: Upload a file
Posted: Fri Nov 14, 2008 5:32 pm
by chopsmith
quick note, like someone said earlier, you need a closing "}" at line 37 (I assume).
Lines 48 and 49. Think it's better to use include("fileName") rather than include 'fileName'. Have you checked to make sure the includes are working?
Line 52. I think you should the values portion should be (and at many places throughout the code):
Code: Select all
"VALUES ('{$fileName}', '{$fileSize}', '{$fileType}', '{$content}')"; //note the {} (or can use . appropriately)
Just some thoughts. Didn't go through too thoroughly. Hope it's helpful.
Re: Upload a file
Posted: Fri Nov 14, 2008 5:35 pm
by chopsmith
Also, have you checked to see if the file actually exists on the system now? And, have you looked at the database to see if there are any records or anything?
Re: Upload a file
Posted: Sat Nov 15, 2008 1:28 pm
by Aravinthan
I did all you told me chopsmith, now it stays blank. THe page doesnt get loaded, not even the title. Here is the code that is showed for this page:
Code: Select all
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html; charset=utf-8"></HEAD>
<BODY></BODY>
<META content=DLWIXOQLDS name=SKYPE_FRAMEID>
<META content=DLWIXOQLDS name=SKYPE_FRAMEID></HTML>
And how can I check if the file exists? I am echoing the file size and type. So I am guessing if file size>0 that means there something that got loaded no?
Re: Upload a file
Posted: Sat Nov 15, 2008 1:52 pm
by mmj
chopsmith wrote:quick note, like someone said earlier, you need a closing "}" at line 37 (I assume).
No, actually he isn't missing a close brace.
chopsmith wrote:Lines 48 and 49. Think it's better to use include("fileName") rather than include 'fileName'. Have you checked to make sure the includes are working?
Not exactly correct. The latter's use is more widespread (including the php manual).
chopsmith wrote:Line 52. I think you should the values portion should be (and at many places throughout the code):
Code: Select all
"VALUES ('{$fileName}', '{$fileSize}', '{$fileType}', '{$content}')"; //note the {} (or can use . appropriately)
Its helps a bit with readability and is better when using assoc arrays but shouldn't really make a difference.
@OP:
Speaking of good practice:
1. don't use addslashes, read up on it if you want to know why. use mysql_real_escape_string.
2. use sprintf for queries. better for security and readability.
since you are using or die on all your queries then they must be going through. Use something like phpmyadmin to see whats going on in the db.
Re: Upload a file
Posted: Sat Nov 15, 2008 5:22 pm
by Aravinthan
I get this: Error QUery failed.....
what is the problem. And I used phpmyadmin and found out that some data inserted in the db.
And I would like to know now is is this section of the code correct(its for displaying the datas and allowing viewrs to download it):
Code: Select all
$Result = mysql_query("SELECT * FROM upload where name like '36Drew' order by id DESC",$link)
or die(mysql_error());
while ($Row = mysql_fetch_row($Result))
{
printf ("<tr><td align='center'>%s</td><td align='center'>%s</td><td align='center'>%s</td></tr>",
$Row[0], $Row[1], $Row[3]);
}
?>
What I want to do is show the record files that contains 36Drew in it.... is it possible?
Re: Upload a file
Posted: Sun Nov 16, 2008 4:37 am
by mmj
Aravinthan wrote:I get this: Error QUery failed.....
what is the problem. And I used phpmyadmin and found out that some data inserted in the db.
And I would like to know now is is this section of the code correct(its for displaying the datas and allowing viewrs to download it):
Code: Select all
$Result = mysql_query("SELECT * FROM upload where name like '36Drew' order by id DESC",$link)
or die(mysql_error());
while ($Row = mysql_fetch_row($Result))
{
printf ("<tr><td align='center'>%s</td><td align='center'>%s</td><td align='center'>%s</td></tr>",
$Row[0], $Row[1], $Row[3]);
}
?>
What I want to do is show the record files that contains 36Drew in it.... is it possible?
Code: Select all
SELECT * FROM upload WHERE name LIKE '%36Drew%' ORDER BY id DESC