Page 4 of 5

Re: Upload a file

Posted: Sun Nov 16, 2008 6:42 am
by Aravinthan
But I still get Errory: QUery Failed for the upload script....

Re: Upload a file

Posted: Sun Nov 16, 2008 8:09 am
by mmj
replace

Code: Select all

mysql_query($query) or die('Error, query failed');
with

Code: Select all

mysql_query($query) or die('Error: ' . mysql_error());
and then post the output that you get.

Re: Upload a file

Posted: Sun Nov 16, 2008 11:31 am
by Aravinthan
Ok this is what I get:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '����O�o�Ϥ�v� d� _�R�2\�N555555���p��B��⿿��'�����������?�笫Q�����?n�'�' at line 1
Those characters are unreadble.....

Re: Upload a file

Posted: Sun Nov 16, 2008 12:17 pm
by mmj
Aravinthan wrote:Ok this is what I get:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '����O�o�Ϥ�v� d� _�R�2\�N555555���p��B��⿿��'�����������?�笫Q�����?n�'�' at line 1
Those characters are unreadble.....
Are you sure the column type is blob for binary data?

I personally don't have much experience inserting binary data into mysql, try Google:

http://google.com/search?q=mysql+insert+binary+data

Re: Upload a file

Posted: Sun Nov 16, 2008 1:19 pm
by Aravinthan
It is blob, and everywhere I look they have almost the same code has me. Only difference the names...
But When I looked at the oder of my rows in phpmyadmin:
id
name
type
size
content

but when I look in my coding:

Code: Select all

 
$query = "INSERT INTO upload (name, size, type, content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";
 
It isnt the same order. Could that be the problem?

Re: Upload a file

Posted: Sun Nov 16, 2008 1:27 pm
by Syntac
No, the order isn't the problem. Use mysql_real_escape_string() to keep your data from clobbering the query.

Re: Upload a file

Posted: Sun Nov 16, 2008 1:30 pm
by Aravinthan
I dont get it Syntac.... where to pu tthe mysql espace...

Re: Upload a file

Posted: Sun Nov 16, 2008 1:39 pm
by mmj
Aravinthan wrote:I dont get it Syntac.... where to pu tthe mysql espace...
http://php.net/mysql_real_escape_string
If binary data is to be inserted, this function must be used.
hmm, maybe that is it.

Re: Upload a file

Posted: Sun Nov 16, 2008 1:45 pm
by Aravinthan
I read the article, but I still dont get where to put the escape string..... is it after my inserted values?

Re: Upload a file

Posted: Sun Nov 16, 2008 2:25 pm
by Syntac
Instead of inserting the raw string, insert the escaped string. Of course, you would know this if you had read the entire page.

Re: Upload a file

Posted: Mon Nov 17, 2008 6:39 am
by Aravinthan
OK I changed my coding to this(first section):

Code: Select all

 
$link = mysql_connect ("localhost", "user", "pass") or die(mysql_error());
mysql_select_db("aoe3clan_division1") or die(mysql_error());
 
$gameid = $_POST['gameid'];
$player1 = $_POST['player1'];
$player2 = $_POST['player2'];
$winner = $_POST['winner'];
$fileName= $player1 . ' vs ' . $player2 . ' on ' . $map;
$tmpName  = mysql_real_escape_string($_FILES['uploaded_file']['tmp_name'], $Link);
$fileSize = mysql_real_escape_string($_FILES['uploaded_file']['size'], $Link);
$fileType = mysql_real_escape_string($_FILES['uploaded_file']['type'], $Link);
 
$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));
fclose($fp);
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: ' . mysql_error());
include 'library/closedb.php';
echo "File $fileName uploaded<br>";
echo $size;
echo $type;
 
I get the message that the file has been uploaded but it has a size of 0 KB, I used phpmyadmin to see it and used mysql to display the results:
http://www.aoe3clan.com/index.php?name=36drew

Thanks for your help

Re: Upload a file

Posted: Mon Nov 17, 2008 9:28 am
by mmj
You aren't calling mysql_real_escape_string on the $content variable.

Re: Upload a file

Posted: Mon Nov 17, 2008 6:22 pm
by Aravinthan
OK I changed it to:

Code: Select all

 
$fp      = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
fclose($fp);
include 'library/config.php';
include 'library/opendb.php';
$content1 = mysql_real_escape_string($content, $Link);
$query = "INSERT INTO upload (name, size, type, content ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$content1')";
mysql_query($query) or die('Error: ' . mysql_error());
include 'library/closedb.php';
echo "File $fileName uploaded<br>";
 
Still no use....

Re: Upload a file

Posted: Fri Nov 21, 2008 6:56 am
by Aravinthan
Any help please?

Re: Upload a file

Posted: Fri Nov 21, 2008 11:14 am
by mmj
There is still no data in the db?